In Qt, signals and slots require matching argument types:
QObject::connect: Incompatible sender/receiver arguments QLabel::linkActivated(QString) --> Button::call(int)
How can I implement a combination like this?
In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.
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. It is even possible to connect a signal directly to another signal.
From the signals slots documentation:
The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)
This means that a signal of the form
signal(int, int, QString)
can only be connected with slots with the following signatures
slot1(int, int, QString)
slot2(int, int)
slot3(int)
slot4()
As koan suggests the best approach is to use another slot with a QString argument and then call the slot you actually want.
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