1
我有一個簡單QObject
:在Qt中,線程完成時對象會發生什麼?
class Engine : public QObject
{
Q_OBJECT
public:
explicit Engine(QObject* parent = 0);
signals:
void finished();
public slots:
void start();
};
實例Engine* engine
存儲在主窗口類中。當按下一個按鈕,將出現以下情況:
QThread* thread = new QThread;
engine->moveToThread(thread);
connect(engine, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
connect(thread, SIGNAL(started()), engine, SLOT(start()));
connect(engine, SIGNAL(finished()), thread, SLOT(quit()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
我的問題是,經過thread
結束會發生什麼engine
?我可以創建另一個線程並將engine
移動到該線程,並重復所有操作?
請注意,與上一個線程的連接仍然存在,除非您要麼銷燬線程,要麼手動斷開連接。 –
當我將'Engine'移動到另一個線程時,(再次)出現「無法移動到目標線程」的錯誤。我應該以某種方式斷開前一個線程中的'Engine'嗎? –