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>
{
Q_OBJECT
public:
public slots:
void AbcInvokeSlot();
};
#endif // 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
To copy to clipboard, switch view to plain text mode
//abc.cpp
#include "abc.h"
{
}
void abc :: AbcInvokeSlot()
{
//some code
}
#include "abc.h"
abc::abc(QObject *parent) :
QObject(parent)
{
}
void abc :: AbcInvokeSlot()
{
//some code
}
To copy to clipboard, switch view to plain text mode
//main.cpp
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();
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();
To copy to clipboard, switch view to plain text mode
I am getting the error :
undefined reference to 'vtable for abc'
I tried changing
abc a;
abc a;
To copy to clipboard, switch view to plain text mode
to
abc a=new abc;
abc a=new abc;
To copy to clipboard, switch view to plain text mode
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??
Bookmarks