Interested in knowing the exact reasoning behind it!!!
-
Hi,
I'm interested in knowing the reason for this.
@
" QObject::connect: No such slot QThread::StopedServiceThread<> in MyThread.cpp"
@Even though I tried to debug the QT4.7.4 framework, but couldn't come with any conclusion.
@
//MyThread.h#include <QThread>
#include<qobject.h>class Mythread : public QThread
{
public:
Mythread(QObject *parent = 0);
~Mythread();void setThreadFlag();
void setDelay();
void run();private:
qint32 stopTheThread;public slots:
void TerminateServiceThread();
void StopedServiceThread();
};#include "Mythread.h"
Mythread::Mythread(QObject *parent)
: QThread(parent)
{stopTheThread = false;
QObject::connect(this, SIGNAL(finished()), this, SLOT(StopedServiceThread()));
}Mythread::~Mythread()
{}
void Mythread::setThreadFlag() {
stopTheThread = true;
}void Mythread::StopedServiceThread() {
printf("Thread stopped\n");
}void Mythread::TerminateServiceThread() {
printf("Thread Got terminated \n");
}
#include <QtCore/QCoreApplication>
#include "Mythread.h"int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);Mythread obj;
obj.start();
obj.setDelay();
obj.setThreadFlag();
return a.exec();
}
@[edit: fixed typo in title, Eddy]
[EDIT: code formatting for error output, Volker] -
Where is "Q_OBJECT":http://doc.qt.nokia.com/4.7/qobject.html#Q_OBJECT macro ?
Edit : You need Q_OBJECT macro, so that MOC (meta Object Compiler) will do the necessary to implement signals and slots . Refer "Meta-Object system":http://doc.qt.nokia.com/4.7/metaobjects.html#meta-object-system
-
The reason is simple if you don't have the Q_OBJECT macro, "the class will not be moc'ed":http://doc.qt.nokia.com/4.7/signalsandslots.html in moc_MyThread.cpp and the slots don't exist.