working on signal and slots on two different classes
-
Hi ,
I am trying to use signal and slots for popping up an qmessagebox window.
The class which emits the signal is inherited from QObject, other who receives the signal is inherited from QWidget and uses macro Q_Object.
I am facing linking error for my code, "undefined reference to signal" . I tried to ass Q_Object macro to the class which emits the signal, this gives undefined reference to `vtable for that class
I am using cmake to build my code.
Please provide inputs. -
Hi ,
I am trying to use signal and slots for popping up an qmessagebox window.
The class which emits the signal is inherited from QObject, other who receives the signal is inherited from QWidget and uses macro Q_Object.
I am facing linking error for my code, "undefined reference to signal" . I tried to ass Q_Object macro to the class which emits the signal, this gives undefined reference to `vtable for that class
I am using cmake to build my code.
Please provide inputs. -
Hi , this is my code snippet
In 1.h file
class A: public QObject, public B{
public signals:
void Sys_SIGNAL();
public:
SYS_DisplayNonCriticalError();
}
1.cpp
A::SYS_DisplayNonCriticalError()
{
emit Sys_SIGNAL();
}
2.h
class MW : public QMainWindow {
Q_OBJECT
public slots:
void GUI_NonCriticalErrorPOP();
}
2.cpp
void MW::init(){
A *SMG_objsysmgr = new A();
connect (SMG_objsysmgr,SIGNAL(Sys_SIGNAL()),this,SLOT(GUI_NonCriticalErrorPOP())); }
void MainWindow::GUI_NonCriticalErrorPOP(){
} -
Hi , this is my code snippet
In 1.h file
class A: public QObject, public B{
public signals:
void Sys_SIGNAL();
public:
SYS_DisplayNonCriticalError();
}
1.cpp
A::SYS_DisplayNonCriticalError()
{
emit Sys_SIGNAL();
}
2.h
class MW : public QMainWindow {
Q_OBJECT
public slots:
void GUI_NonCriticalErrorPOP();
}
2.cpp
void MW::init(){
A *SMG_objsysmgr = new A();
connect (SMG_objsysmgr,SIGNAL(Sys_SIGNAL()),this,SLOT(GUI_NonCriticalErrorPOP())); }
void MainWindow::GUI_NonCriticalErrorPOP(){
}@Sriu1 said in working on signal and slots on two different classes:
seems about right, just one thing, add
Q_OBJECT
also to the class that emits the signal.
Also to be on the save side, rerun qmake after you made that change.

-
@Sriu1 said in working on signal and slots on two different classes:
seems about right, just one thing, add
Q_OBJECT
also to the class that emits the signal.
Also to be on the save side, rerun qmake after you made that change.

-
Hi,
Then do a clean rebuild of your project. That will be faster.
-
mmh,
just to be sure:
did you#include <QObject>to the class? -
Hi
adding to @J-Hilk
Did you also read, understand and setup moc for Cmake ?
https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOMOC.html