View Full Version : Incompatible sender/receiver arguments

6th May 2011, 11:02
I have 2 classes A and B

class A has a signal emitMessage(QString)
class B has a slot showMessage(QString, int)

is there a way to connect these two with constant int value, something like

connect(A, SIGNAL(emitCritical(QString, 5)), B, SLOT(showMessage(QString, int)));

connect(A, SIGNAL(emitCritical(QString)), B, SLOT(showMessage(QString, 5)));

I know that if signal had more arguments, they will be ignored in slot, but is it possible to have default values for slot arguments

6th May 2011, 11:17
Try QSignalMapper

6th May 2011, 11:21
... is it possible to have default values for slot arguments
Yes, but if you have a function with default argument let's call it void foo(QString &s, int i = 10) how do you call it with default i value? Like this: foo(some_qstring); so delete the magic 5 from the connection.

6th May 2011, 11:44
I kind of tried that before i started this thread but i wrote
in declaration showMessage(QString, int)
in definition showMessage(QString msg, int interval = 5)

the correct answer was
in declaration showMessage(QString, int = 5)
in definition showMessage(QString msg, int interval)

now i can connect them with
connect(A, SIGNAL(emitCritical(QString)), B, SLOT(showMessage(QString)));

Thanks for your help,