A TQThread 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(), TQThreads begin executing in run(). You inherit run() to include your code. For example:
This 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().
.PP
See also Thread Support in Qt, Environment Classes, and Threading.
Constructs a new thread. The thread does not begin executing until start() is called.
.PP
If \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.
Note that deleting a TQThread object will not stop the execution of the thread it represents. Deleting a running TQThread (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.
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.
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.
Begins execution of the thread by calling run(), which should be reimplemented in a TQThread subclass to contain your code. The operating system will schedule the thread according to the \fIpriority\fR argument.
This function terminates the execution of the thread. The thread may or may not be terminated immediately, depending on the operating system's scheduling policies. Use TQThread::wait() after terminate() for synchronous termination.
When 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 terminated 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.
The thread associated with this TQThread 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.
\fItime\fR milliseconds has elapsed. If \fItime\fR is ULONG_MAX (the default), then the wait will never timeout (the thread must return from run()). This function will return FALSE if the wait timed out.
.PP
This provides similar functionality to the POSIX \fCpthread_join()\fR function.