Unsolved Error if I pass arguments to connect in
-
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.
-
@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 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. -
@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
-
@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.
-
@Pradeep-Kumar yes you can.
-
-
@Pradeep-Kumar I don't think it's new - it is probably working since C++ allows default values :-)
-
-
You can use the new connect syntax to make this work:
connect(act, &QAction::triggered, this, [this]()->void{writeimage(QStringLiteral("currrent"));});