A question about connect funtion
-
Assuming that there is signal fooSig(const QString& str), and if I wrote the connect funtion like connect(this, SIGNAL(fooSig(QString))...), it will work well. This is confused, shouldn't it be the prototype of the signal function(of course without return type) in the parethesis of SIGNAL?
-
@Saymyname
Don't use theSIGNAL
/SLOT()
old-styleconnect()
syntax which was superseded over a decade ago. Use the New Signal Slot Syntax which is preferable for a number of reasons, including avoiding your issue and making it much clearer. -
@johnsmith3321 Thank you for you answer, that's pretty comprehensive about how to use those two macros
-
@Saymyname
So your case would become:connect(this, &MyClass::fooSig, this, &MyClass::fooSlot);
Don't you think this is nicer? It is also checked at compile time, so you will get a compilation error if the signal or slot does not exist or does not take the right arguments.