[Solved] Slot is not recognized
-
Hello,
I have a small problem with a slot, my connect doesn't work because
@QObject::connect: No such slot ctrlMachine::MainForm::onAxis_error(QString) in .\ctrlMachine.cpp:94@
I think that I have to find another way to write my slot, but I also tried with an object, without changes.ctrlMachine.cpp:
@#include "ctrlMachine.h"this->connect(axisCamX, SIGNAL( signalError(QString) ), SLOT(MainForm::onAxis_error(QString)));@
ctrlMachine.h:
@#include "mainform.h"class ctrlMachine : public QObject {.....etc }; @
mainform.cpp:
@#include "mainform.h"
#include "ctrlMachine.h"void MainForm::onAxis_error(QString msg)
{
QMessageBox msgBox;
msgBox.setText("ERROR");
msgBox.setInformativeText( msg );
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Close);
msgBox.setDefaultButton(QMessageBox::Close);
msgBox.exec();
}
@
mainform.h:
@#include "ui_mainform.h"class ctrlMachine;
class MainForm : public QMainWindow
{
Q_OBJECTpublic slots:
void onAxis_error(QString msg);private:
Ui::MainForm *ui;
ctrlMachine *machine; ....etc };@
Is "MainForm::onAxis_error(QString)" right in my slot? Would anyone know how to solve the problem? Thank you in advance -
Hi,
There are 2 issues with your connect() statement:
You forgot to include the pointer to your MainForm object.
You shouldn't write the "MainForm::" in front of "onAxis_error".
@
this->connect(axisCamX, SIGNAL(signalError(QString)),
mainForm, SLOT(onAxis_error(QString)));
@ -
[quote author="silep" date="1397649969"]JKSH: Do you mean the pointer this? How can I add it to my MainForm? I don't understand[/quote]See the code in my previous post. There are 4 arguments (but your code only has 3). The syntax is
@
connect(pointerToSender, SIGNAL(nameOfSignal()),
pointerToReceiver, SLOT(nameOfSlot()));
@ -
Just to clarify there is an overload of the "old" QObject::connect function that takes only 3 arguments, if the slot is the defined in the same QObject class.
@
connect(sender, SIGNAL(...), this, SLOT(...));
// should be the same as
connect(sender, SIGNAL(...), SLOT(...));
@As far as I know that only works for the old connect syntax, if you are using Qt5 with function pointers you have to use 4 arguments I think.