Unsolved 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, @Sriu1
wihtout actually seeing your code, I can only take a guess.
But it sounds like the signal you're emitting, is not marked with the Q_SIGNAL makro or you're trying to missuse an actual function as a signal
-
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.
-
@J.Hilk
I am using cmake to build my code, after adding Q_OBJECT, i am facing "undefined reference to `vtable for A" -
Hi,
Then do a clean rebuild of your project. That will be faster.
-
@SGaist
I have been doing clean build , but no luck..
Same errors exist..
My code isn't generating moc file for 1.cpp file.. Hence vtable error still exists..
Could you please suggest a solution for it.. -
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