connecting signal from thread to slot in a cpp file
I am trying to connect a signal from a thread to a slot in a cpp file.
I am able to successfully connect it to Main Window slot,but not through a cpp file.
Here is what I am doing
//abc.h
Code:
#ifndef ABC_H
#define ABC_H
#include <QObject>
{
Q_OBJECT
public:
public slots:
void AbcInvokeSlot();
};
#endif // ABC_H
//abc.cpp
Code:
#include "abc.h"
{
}
void abc :: AbcInvokeSlot()
{
//some code
}
//main.cpp
Code:
MainWindow win;
abc a;
win.show();
SThread sthread;
QObject::connect( & sthread,
SIGNAL( SInSignal
() ),
& win,
SLOT( SOutSlot
() ) );
//correctly working QObject::connect( & sthread,
SIGNAL( SInSignal
() ),
& a,
SLOT( AbcInvokeSlot
() ) );
//not working sthread.start();
return app.exec();
I am getting the error :
Quote:
undefined reference to 'vtable for abc'
I tried changing
to
then I am getting this error:
Quote:
no matching function for call to 'QObject::connect(SThread*, const char*, abc**, const char*)'
May I know what I am doing wrong and what is the correct procedure??
Re: connecting signal from thread to slot in a cpp file
Rerun qmake and rebuild your program.
Re: connecting signal from thread to slot in a cpp file
As ChrisW67 said, run qmake again.
Your code is fine, the error is caused by adding Q_OBJECT to a header after the header has been added to the project file and the related qmake run.
Classes with Q_OBJECT need to be processed by MOC and these processing instructions are created by qmake.
If you add Q_OBJECT after a header file has been "seen" by qmake, then certain bit will be missing at link time.
Rerunning qmake (and completing the hew build) solves that.
Cheers,
_
Re: connecting signal from thread to slot in a cpp file
Thank you for the solution and explanation.It exactly solved my problem!!