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, 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?
A simple method is to have an intermediate slot that calls the slot that you want. e.g.
and then
You have to define some way to interpret the string into an int.
From the signals slots documentation:
This means that a signal of the form
signal(int, int, QString
)can only be connected with slots with the following signatures
As koan suggests the best approach is to use another slot with a QString argument and then call the slot you actually want.
Default values for slot parameters helps very well. This allow to connect signals with different signatures to slot (vice versa to @pnezis answer):
may be connected to different signals:
Also Qt 4.8 suggest useful QSignalMapper class:
But only for one parameter:
As a complementary answer, if you don't want to write an intermediate slot, you can use the lambda expressions (of course with C++11 support) to invoke the method. However, the connector class must know the parameter types used in those particular signals and slots.
To give an example, assuming that you're trying to connect a signal with a parameter type of
QString
to a slot with a parameter type ofchar
, you can do it like this;Kinda ugly stuff, but does the job.