Error if I pass arguments to connect in
-
connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));
gives me error Object::connect: No such slot GQActions::writeimage(QString("all"))
Object::connect: No such slot GQActions::writeimage(QString("all"))but If I do not pass any argument in writeimage then I do not get error
connect(act, SIGNAL(triggered()), this, SLOT(writeimage());it is working fine
-
connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));
gives me error Object::connect: No such slot GQActions::writeimage(QString("all"))
Object::connect: No such slot GQActions::writeimage(QString("all"))but If I do not pass any argument in writeimage then I do not get error
connect(act, SIGNAL(triggered()), this, SLOT(writeimage());it is working fine
@Qt-Enthusiast you can not pass parameters to slots in connect!
Parameters are passed from signal when it is emitted. -
connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));
gives me error Object::connect: No such slot GQActions::writeimage(QString("all"))
Object::connect: No such slot GQActions::writeimage(QString("all"))but If I do not pass any argument in writeimage then I do not get error
connect(act, SIGNAL(triggered()), this, SLOT(writeimage());it is working fine
As said by @jsulm ,
connect(act, SIGNAL(triggered()), this, SLOT(writeimage()));
both the signatures must be same.If you have any values to be passed, can provide only datatypes.
Ex:
connect(act, SIGNAL(triggered(bool)), this, SLOT(writeimage(bool)));Thanks,
-
As said by @jsulm ,
connect(act, SIGNAL(triggered()), this, SLOT(writeimage()));
both the signatures must be same.If you have any values to be passed, can provide only datatypes.
Ex:
connect(act, SIGNAL(triggered(bool)), this, SLOT(writeimage(bool)));Thanks,
@Pradeep-Kumar @Qt-Enthusiast Actually the signal can have more parameters than the slot - the slot then just ignores all the other parameters.
The thing is:connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));this is not a valid connect call as QString("currrent") creates a QString instance. If writeimage has a QString parameter then it should be:
connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString)));but even then it is wrong as the signal does not have QString parameter.
-
@Pradeep-Kumar @Qt-Enthusiast Actually the signal can have more parameters than the slot - the slot then just ignores all the other parameters.
The thing is:connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));this is not a valid connect call as QString("currrent") creates a QString instance. If writeimage has a QString parameter then it should be:
connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString)));but even then it is wrong as the signal does not have QString parameter.
@jsulm @Pradeep-Kumar @Qt-Enthusiast
can pass a default parameters to the SIGNAL, to somewhat circumvent the issue
signals: void signalDefault(QString s = "foo"); private slots: void slotDefault(QString s){ // do stuff } //in cpp connect(this, SIGNAL(signalDefault(QString)), this, SLOT(slotDefault(QString))); emit signalDefault(); -
@jsulm @Pradeep-Kumar @Qt-Enthusiast
can pass a default parameters to the SIGNAL, to somewhat circumvent the issue
signals: void signalDefault(QString s = "foo"); private slots: void slotDefault(QString s){ // do stuff } //in cpp connect(this, SIGNAL(signalDefault(QString)), this, SLOT(slotDefault(QString))); emit signalDefault(); -
@jsulm @Pradeep-Kumar @Qt-Enthusiast
can pass a default parameters to the SIGNAL, to somewhat circumvent the issue
signals: void signalDefault(QString s = "foo"); private slots: void slotDefault(QString s){ // do stuff } //in cpp connect(this, SIGNAL(signalDefault(QString)), this, SLOT(slotDefault(QString))); emit signalDefault();@J.Hilk ,
can we use as u mentioned,
signals:
void signalDefault(QString s = "foo");and emit without argument?.
emit signalDefault();
Thanks,
-
@J.Hilk ,
can we use as u mentioned,
signals:
void signalDefault(QString s = "foo");and emit without argument?.
emit signalDefault();
Thanks,
@Pradeep-Kumar just try
-
@J.Hilk I never tried, did you?
But even if it is working I wouldn't do this because you're hiding in your code what you actually pass to the connected slots.@jsulm said in Error if I pass arguments to connect in:
@J.Hilk I never tried, did you?
But even if it is working I wouldn't do this because you're hiding in your code what you actually pass to the connected slots.I did, I have one or 2 such case in my current project, it even work with both new and old SIGNAL/SLOT syntax. I believe that changed recently, as I remember it working only with the old one.
-
@J.Hilk ,
can we use as u mentioned,
signals:
void signalDefault(QString s = "foo");and emit without argument?.
emit signalDefault();
Thanks,
@Pradeep-Kumar yes you can.
-
@jsulm , @J-Hilk ,
yes i tried, i am getting the value in slot,
so is it the new way, or was present earlier also. just curious.
Thanks,
-
@jsulm , @J-Hilk ,
yes i tried, i am getting the value in slot,
so is it the new way, or was present earlier also. just curious.
Thanks,
@Pradeep-Kumar I don't think it's new - it is probably working since C++ allows default values :-)
-
@Pradeep-Kumar I don't think it's new - it is probably working since C++ allows default values :-)