⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qthread.3qt

📁 Trolltech公司发布的基于C++图形开发环境
💻 3QT
字号:
'\" t.TH QThread 3qt "24 January 2005" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS.  All rights reserved.  See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQThread \- Platform-independent threads.br.PP\fC#include <qthread.h>\fR.PPInherits Qt..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQThread\fR () ".br.ti -1c.BI "virtual \fB~QThread\fR () ".br.ti -1c.BI "bool \fBwait\fR ( unsigned long " "time" " = ULONG_MAX ) ".br.ti -1c.BI "void \fBstart\fR () ".br.ti -1c.BI "bool \fBfinished\fR () const".br.ti -1c.BI "bool \fBrunning\fR () const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "HANDLE \fBcurrentThread\fR () ".br.ti -1c.BI "void \fBpostEvent\fR ( QObject *, QEvent * ) ".br.ti -1c.BI "void \fBexit\fR () ".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBrun\fR () ".br.in -1c.SS "Static Protected Members".in +1c.ti -1c.BI "void \fBsleep\fR ( unsigned long ) ".br.ti -1c.BI "void \fBmsleep\fR ( unsigned long ) ".br.ti -1c.BI "void \fBusleep\fR ( unsigned long ) ".br.in -1c.SH DESCRIPTIONThe QThread class provides platform-independent threads.PPA QThread represents a separate thread of control within the program; it shares all data with other threads within the process but executes independently in the way that a separate program does on a multitasking operating system. Instead of starting in main(), however, QThreads begin executing in run(), which you inherit to provide your code. For instance:.PP.nf.br  class MyThread : public QThread {.br.br  public:.br.br    virtual void run();.br.br  };.br.br  void MyThread::run().br  {.br    for(int count=0;count<20;count++) {.br      sleep(1);.br      qDebug("Ping!");.br    }.br  }.br.br  int main().br  {.br      MyThread a;.br      MyThread b;.br      a.start();.br      b.start();.br      a.wait();.br      b.wait();.br  }.fi.PPThis will start two threads, each of which writes Ping! 20 times to the screen and exits. The wait() calls at the end of main() are necessary because exiting main() ends the program, unceremoniously killing all other threads. Each MyThread stops executing when it reaches the end of MyThread::run(), just as an application does when it leaves main()..PPSee also the paragraph on Thread Support in Qt.SH MEMBER FUNCTION DOCUMENTATION.SH "QThread::QThread ()"Constructs a new thread. The thread does not actually begin executing until start() is called..SH "QThread::~QThread () \fC[virtual]\fR"QThread destructor. Note that deleting a QThread object will not stop the execution of the thread it represents, and that deleting a QThread object while the thread is running is unsafe..SH "HANDLE QThread::currentThread () \fC[static]\fR"This returns the thread handle of the currently executing thread. The handle returned by this function is used for internal reasons and should not be used in any application code. On Windows, the returned value is a pseudo handle for the current thread, and it can not be used for numerical comparison..SH "void QThread::exit () \fC[static]\fR"Ends execution of the calling thread and wakes up any threads waiting for its termination..SH "bool QThread::finished () const"Returns TRUE is the thread is finished..SH "void QThread::msleep ( unsigned long msecs ) \fC[static protected]\fR"System independent sleep. This causes the current thread to sleep for \fImsecs\fR milliseconds..SH "void QThread::postEvent ( QObject * receiver, QEvent * event ) \fC[static]\fR"Provides a way of posting an event from a thread which is not the event thread to an object. The event is put into a queue, then the event thread is woken which then sends the event to the object. It is important to note that the event handler for the event, when called, will be called from the event thread and not from the thread calling QThread::postEvent()..PPSame as with QApplication::postEvent(), \fIevent\fR must be allocated on the heap, as it is deleted when the event has been posted..SH "void QThread::run () \fC[virtual protected]\fR"This method is pure virtual, and it must be implemented in derived classes in order to do useful work. Returning from this method will end execution of the thread..SH "bool QThread::running () const"Returns TRUE if the thread is running..SH "void QThread::sleep ( unsigned long secs ) \fC[static protected]\fR"System independent sleep. This causes the current thread to sleep for \fIsecs\fR seconds..SH "void QThread::start ()"This begins actual execution of the thread by calling run(), which should be reimplemented in a QThread subclass to contain your code. If you try to start a thread that is already running, this call will wait until the thread has finished, and then restart the thread..SH "void QThread::usleep ( unsigned long usecs ) \fC[static protected]\fR"System independent sleep. This causes the current thread to sleep for \fIusecs\fR microseconds..SH "bool QThread::wait ( unsigned long time = ULONG_MAX )"This allows similar functionality to POSIX pthread_join. A thread calling this will block until one of 2 conditions is met:.TPThe thread associated with this QThread object has finished execution (i.e. when it returns from run() ). This function will return TRUE if the thread has finished. It also returns TRUE if the thread has not been started yet..TP \fItime\fR milliseconds has elapsed.  If \fItime\fR is ULONG_MAX (defaultargument), then the wait will never timeout (the thread mustreturn from run() ).  This function will return FALSEif the wait timed out..SH "SEE ALSO".BR http://doc.trolltech.com/qthread.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com.  See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qthread.3qt) and the Qtversion (2.3.10).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -