Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt question: How do signals and slots work?

Tags:

c++

qt

How do signals and slots work at a high level abstraction?

How are signals and slots implemented at a high level abstraction?

like image 695
Trevor Boyd Smith Avatar asked Sep 02 '09 16:09

Trevor Boyd Smith


People also ask

How many signals can be connected to a slot in Qt?

You can have as many signals you want connected to one slot and vice versa. If several slots are connected to one signal, the slots will be executed one after the other, in the order they have been connected, when the signal is emitted.

Are Qt signals and slots thread safe?

It is generally unsafe to provide slots in your QThread subclass, unless you protect the member variables with a mutex. On the other hand, you can safely emit signals from your QThread::run() implementation, because signal emission is thread-safe.

Can you connect one Qt to multiple slots?

Just as an object does not know if anything receives its signals, a slot does not know if it has any signals connected to it. This ensures that truly independent components can be created with Qt. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need.


1 Answers

I've actually read this Qt page about it, and it does a good job of explaining:

https://doc.qt.io/qt-5/signalsandslots.html

like image 197
Neil Avatar answered Nov 03 '22 06:11

Neil