Exactly. But you can easily work it around by creating another object which lives in the correct thread and move those slots there:
class ReconstructionObject
: public QObject { ...
public slots:
void startMethod(int iToStart);
void stopMethod(int iToStop);
signals:
void methodFinished();
};
class ReconstructionObject : public QObject {
...
public slots:
void startMethod(int iToStart);
void stopMethod(int iToStop);
signals:
void methodFinished();
};
To copy to clipboard, switch view to plain text mode
Then you have two options: 1) create ReconstructionObject in ReconstructionThread::run():
void ReconstructionThread::run()
{
ReconstructionObject object;
// connect signals and slots
exec();
}
void ReconstructionThread::run()
{
ReconstructionObject object;
// connect signals and slots
exec();
}
To copy to clipboard, switch view to plain text mode
or 2) create it somewhere outside and use QObject::moveToThread():
ReconstructionThread* thread = new ReconstructionThread(parent);
ReconstructionObject* object = new ReconstructionObject;
object->moveToThread(thread);
thread->start();
// and for example something like this to handle cleanup
connect(object, SIGNAL(methodFinished()), object, SLOT(deleteLater()));
connect(object, SIGNAL(destroyed()), thread , SLOT(quit()));
connect(thread, SIGNAL(finished()), thread , SLOT(deleteLater()));
ReconstructionThread* thread = new ReconstructionThread(parent);
ReconstructionObject* object = new ReconstructionObject;
object->moveToThread(thread);
thread->start();
// and for example something like this to handle cleanup
connect(object, SIGNAL(methodFinished()), object, SLOT(deleteLater()));
connect(object, SIGNAL(destroyed()), thread , SLOT(quit()));
connect(thread, SIGNAL(finished()), thread , SLOT(deleteLater()));
To copy to clipboard, switch view to plain text mode
Bookmarks