简体   繁体   中英

Qt Signals and slot thread safety

Let's say I have a signal change connected to a slot notify. If the change signal is emitted, the notify slot will start executing.

Now what happens if a second change signal is emitted and the first notify slot didn't finish its execution?

Is the second slot launched concurrently with the first? And if so, is Qt handling the thread-safety or it's up to the programmer to handle it?

It depends on connection type you specified via calling connect function. The only way when slot will be launched concurrently is if you specified Qt::DirectConnection AND emitting signal in thread different from slot's thread. If you omit connection type, it would be Qt::AutoConnection . In this case if you emit a signal from one thread, and catching it in another one (eg in main GUI thread) - Qt will put a slot's call to the message queue and will make all calls sequentially. Read this for further info - http://qt-project.org/doc/qt-4.8/threads-qobject.html#signals-and-slots-across-threads

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