简体   繁体   中英

Qt application with multiple threads

I have a QT application.

I have a thread (ex thread1 ) that shows my mainwindow (so this is different from the main thread).

I also have my own thread (ex thread2 ) must notify the thread1 updating my GUI. There is a quick way to do this? ex: thread2 may decide to update an image: so, he shall notify the thread1 to perform the method changeImage() .

If I do run this method directly from thread2 my application will have a crash. I must to use pthread.

Only the main thread should update the GUI (for restrictions due to graphical systems).

However, Qt has enhanced thread support allowed by signal-slot connections across threads. In facts, the other threads have to notify the main thread using signals ( emit my_signal() see http://qt-project.org/doc/qt-4.8/signalsandslots.html ) or using QCoreApplication::postEvent ( http://qt-project.org/doc/qt-4.8/qcoreapplication.html#postEvent-2 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM