Only thing I can see is that some connect is called after you create an instance of MyObject. I don't know when start() of MyObject is called. I can only guess, but if it is in the constructor, then you can have the signal "processFinished" emitted before calling "connect" on it. If only thing called in the Threads "run" method is the emit statement, then you have a perfect example of a single threaded processing.
Show us full code or we will guess like this for next 1000 posts.
Look, this is what I mean:
// not multi-threaded
#include <QThread>
#include <QDebug>
#include <QCoreApplication>
Q_OBJECT
public:
}
void run(){
qDebug
() <<
"thread in run(): " <<
QThread::currentThread();
emit signal1();
}
signals:
void signal1();
};
Q_OBJECT
public:
{
Thread * thread = new Thread(this);
connect(thread, SIGNAL(signal1()), this, SLOT(aSlot()));
thread->run();
}
public slots:
void aSlot(){
qDebug
() <<
"A SLOT: " <<
QThread::currentThread();
}
};
int main(int argc, char ** argv){
qDebug
() <<
"thread in main(): " <<
QThread::currentThread();
MyObject obj;
qDebug() << "before exec()";
return 0;
}
// not multi-threaded
#include <QThread>
#include <QDebug>
#include <QCoreApplication>
class Thread : public QThread{
Q_OBJECT
public:
Thread(QObject * parent = NULL) : QThread(parent){
}
void run(){
qDebug() << "thread in run(): " << QThread::currentThread();
emit signal1();
}
signals:
void signal1();
};
class MyObject : public QObject{
Q_OBJECT
public:
MyObject(QObject * parent = NULL) : QObject(parent)
{
Thread * thread = new Thread(this);
connect(thread, SIGNAL(signal1()), this, SLOT(aSlot()));
thread->run();
}
public slots:
void aSlot(){
qDebug() << "A SLOT: " << QThread::currentThread();
}
};
int main(int argc, char ** argv){
QCoreApplication app(argc,argv);
qDebug() << "thread in main(): " << QThread::currentThread();
MyObject obj;
qDebug() << "before exec()";
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks