Qt question: How do signals and slots work?


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

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

9/3/2009 7:44:12 AM

Accepted Answer

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


4/30/2013 10:50:12 AM

As other people said, there's very good Qt documetnation available for this topic. If you want to know what happens under the hood, this info might help you:

Slots are just regular methods. Nothing special there, EXCEPT moc will save their signature in a table in the intermediate .moc file - you can see this table quite clearly when you look through this file.

This table allows you to call a method using it's signature. The SLOT(mySlot(int)) macro boils down to a string representation of the method in question. There are several ways you can do this, see the documentation for QMetaObject for example.

When a you connect a signal to a slot, the signal and slot signatures are stored for later use. When a signal is emitted, all the slots previously connected to that signal are called using the method described above.

If you want to know more, I suggest looking through the moc-generated code, and stepping through a signal emission and the internals of the connect() call. There's no magic here, but there is a lot of cleverness.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow