Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do a check of the signal/slot connect's during compilation?

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?

like image 415
Phil Hannent Avatar asked Jan 03 '12 09:01

Phil Hannent


People also ask

What is signal slot connection?

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.

How do you wait for a signal in Qt?

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.

Why do we need signals and slots when we can directly call 2 objects using their member functions?

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.


2 Answers

Using QT5 you can use the following syntax which is statically checked at compile time:

connect(sender, &Sender::signalMethod,  receiver, &Receiver::slotMethod);
like image 90
Pierluigi Avatar answered Sep 19 '22 09:09

Pierluigi


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.

like image 30
BЈовић Avatar answered Sep 20 '22 09:09

BЈовић