PDA

View Full Version : Incompatible sender/receiver arguments



davidovv
6th May 2011, 10: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)));

or
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

nightghost
6th May 2011, 10:17
Try QSignalMapper

Zlatomir
6th May 2011, 10: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.

davidovv
6th May 2011, 10: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,