What is the best practice for communicating with another thread in Qt?

I have a class derived from QThread that binds to the main thread, sending QEvents to it.

What is the best way for the main thread to interact with the second thread?

The main thread has a pointer to the second.

+3
source share
1 answer

The best way to communicate between objects in Qt is to use signals and slots. This is a thread-safe method that is handled by an event loop and does not require blocking on your part. You can also use events, although this use seems a little strange - an event is a notification of what is happening, not a tool for communication.

, QMutex, QSemaphore, QWaitCondition QReadWriteLock ( , QMutex, , , ).

Qt, , Qt.

+5

Source: https://habr.com/ru/post/1743687/


All Articles