📄 qthread.3qt
字号:
'\" t.TH QThread 3qt "9 December 2002" "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.SH SYNOPSISAll the functions in this class are thread-safe when Qt is built with thread support.</p>.PP\fC#include <qthread.h>\fR.PPInherits Qt..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQThread\fR ()".br.ti -1c.BI "\fBQThread\fR ( unsigned int stackSize )".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 "void \fBterminate\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 "Qt::HANDLE \fBcurrentThread\fR ()".br.ti -1c.BI "void postEvent ( QObject * receiver, QEvent * event ) \fI(obsolete)\fR".br.ti -1c.BI "void \fBexit\fR ()".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBrun\fR () = 0".br.in -1c.SS "Static Protected Members".in +1c.ti -1c.BI "void \fBsleep\fR ( unsigned long secs )".br.ti -1c.BI "void \fBmsleep\fR ( unsigned long msecs )".br.ti -1c.BI "void \fBusleep\fR ( unsigned long usecs )".br.in -1c.SH DESCRIPTIONThe QThread class provides platform-independent threads..PPA QThread represents a separate thread of control within the program; it shares data with all the 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(), QThreads begin executing in run(). You inherit run() to include your code. For example:.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 }.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 Thread Support in Qt, Environment Classes, and Threading..SH MEMBER FUNCTION DOCUMENTATION.SH "QThread::QThread ()"Constructs a new thread. The thread does not begin executing until start() is called..SH "QThread::QThread ( unsigned int stackSize )"Constructs a new thread. The thread does not begin executing until start() is called..PPIf \fIstackSize\fR is greater than zero, the maximum stack size is set to \fIstackSize\fR bytes, otherwise the maximum stack size is automatically determined by the operating system..PP\fBWarning:\fR Most operating systems place minimum and maximum limits on thread stack sizes. The thread will fail to start if the stack size is outside these limits..SH "QThread::~QThread ()\fC [virtual]\fR"QThread destructor..PPNote that deleting a QThread object will not stop the execution of the thread it represents. Deleting a running QThread (i.e. finished() returns FALSE) will probably result in a program crash. You can wait() on a thread to make sure that it has finished..SH "Qt::HANDLE QThread::currentThread ()\fC [static]\fR"This returns the thread handle of the currently executing thread..PP\fBWarning:\fR The handle returned by this function is used for internal purposes and should \fInot\fR be used in any application code. On Windows, the returned value is a pseudo handle for the current thread, and it cannot be used for numerical comparison..SH "void QThread::exit ()\fC [static]\fR"Ends the 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; otherwise returns FALSE..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"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPUse QApplication::postEvent() instead..SH "void QThread::run ()\fC [pure virtual protected]\fR"This method is pure virtual, and must be implemented in derived classes in order to do useful work. Returning from this method will end the execution of the thread..PPSee also wait()..SH "bool QThread::running () const"Returns TRUE if the thread is running; otherwise returns FALSE..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 the 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::terminate ()"This function terminates the execution of the thread. The thread may or may not be terminated immediately, depending on the operating systems scheduling policies. Use QThread::wait() after terminate() for synchronous termination..PPWhen the thread is terminated, all threads waiting for the the thread to finish will be woken up..PP\fBWarning:\fR This function is dangerous, and its use is discouraged. The thread can be terminate at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to cleanup after itself, unlock any held mutexes, etc. In short, use this function only if \fIabsolutely\fR necessary..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 provides similar functionality to POSIX pthread_join. A thread calling this will block until either of these 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 (thedefault), then the wait will never timeout (the thread mustreturn from run()). This function will return FALSE if thewait 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 help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qthread.3qt) and the Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -