Checking the Qt signal slot connect calls at runtime is a worry for me. I should be possible to run a static check of the connect statements.
Does such a tool exist?
A slot is called when a signal connected to it is emitted. Slots are normal C++ functions and can be called normally; their only special feature is that signals can be connected to them. Since slots are normal member functions, they follow the normal C++ rules when called directly.
You can use a local event loop to wait for the signal to be emitted : QTimer timer; timer. setSingleShot(true); QEventLoop loop; connect( sslSocket, &QSslSocket::encrypted, &loop, &QEventLoop::quit ); connect( &timer, &QTimer::timeout, &loop, &QEventLoop::quit ); timer.
A public slots section contains slots that anyone can connect signals to. This is very useful for component programming: you create objects that know nothing about each other, connect their signals and slots so that information is passed correctly, and, like a model railway, turn it on and leave it running.
Using QT5 you can use the following syntax which is statically checked at compile time:
connect(sender, &Sender::signalMethod, receiver, &Receiver::slotMethod);
Does such a tool exist?
It would be nice if such tool would existed, but unfortunately it doesn't exist, because of the way signal/slot mechanism is implemented in qt. Also, for that reason it is not possible to statically check whether signal fit into the slot.
If qt used something like boost's signal/slots it would be possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With