prkhr4u
17th February 2014, 05:09
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
#ifndef ABC_H
#define ABC_H
#include <QObject>
class abc : public QObject
{
Q_OBJECT
public:
explicit abc(QObject *parent = 0);
public slots:
void AbcInvokeSlot();
};
#endif // ABC_H
//abc.cpp
#include "abc.h"
abc::abc(QObject *parent) :
QObject(parent)
{
}
void abc :: AbcInvokeSlot()
{
//some code
}
//main.cpp
QApplication app(argc, argv);
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 :
undefined reference to 'vtable for abc'
I tried changing
abc a;
to
abc a=new abc;
then I am getting this error:
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??
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
#ifndef ABC_H
#define ABC_H
#include <QObject>
class abc : public QObject
{
Q_OBJECT
public:
explicit abc(QObject *parent = 0);
public slots:
void AbcInvokeSlot();
};
#endif // ABC_H
//abc.cpp
#include "abc.h"
abc::abc(QObject *parent) :
QObject(parent)
{
}
void abc :: AbcInvokeSlot()
{
//some code
}
//main.cpp
QApplication app(argc, argv);
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 :
undefined reference to 'vtable for abc'
I tried changing
abc a;
to
abc a=new abc;
then I am getting this error:
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??