Cross-platform multithreaded development can be achieved through qthread, and the QT Library is responsible for specific multithreaded implementations on specific platforms. To use Qthread for multithreaded development, you first need to include a header file:
#include <QThread> then need to inherit a thread class from Qthread, Mythread, the key is to implement a virtual function run in Qthread. At the end of the run function, exec () is usually called, which causes the thread to enter the event loop, otherwise the thread's main function runs and the thread exits. Class Mythread:public Qthread{public:mythread ();p ublic:dialog *parent;public:void Run ();}; Where the parent stores the window that created the thread, the parent thread of that thread, which is used primarily to send specific events to the parent thread for inter-thread communication. The custom message first needs to include the header file: #include <QEvent> then define your own event values: const Qevent::type myevent = (qevent::type) 1234; And then inside the run function (in fact, in any place where you want to communicate with the parent thread, I'm simplifying here to be inside the Run function) by: qapplication::p ostevent (parent, New Qevent (MyEvent)); Send the event out. The parent thread is able to capture the message by overwriting the virtual function event: bool Dialog::event (qevent *event) {if (event->type () = = MyEvent) {Qmessagebox::inf Ormation (This, "information", "This is son sented signal!"); return true; } return Qwidget::event (event);} In this way, two threads can run concurrently and be able to communicate between threads.
Http://www.cnblogs.com/bingcaihuang/archive/2011/03/16/1985971.html
Qt multithreading and communication via events (via custom events, then qapplication::p ostevent to the main interface, I used a signal slot)