Furthermore, since postEvent() is thread-safe, we can use it from any thread to post events to the GUI thread. Qt's event mechanism allows us to define custom event types in addition to the built-in types, and allows us to post events of these types using QApplication::postEvent(). The solution for communicating from a non-GUI thread to the GUI thread is to use custom events. But none of these techniques can be used to communicate with the GUI thread, since they would lock the event loop and freeze the user interface. If these new threads need to communicate among themselves, they can use shared variables together with mutexes, semaphores, or wait conditions. The GUI thread can start new threads by creating objects of a QThread subclass, as we did in the previous section. After the call to exec(), this thread is either waiting for an event or processing an event. For this reason, we normally refer to this thread as the GUI thread. This is the only thread that is allowed to create the QApplication object and call exec() on it. When a Qt application starts, only one thread is runningthe initial thread.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |