我剛剛開始在Windows上使用Qt並閱讀有關moveToThread()函數。如果我這樣寫:Qt C++ moveToThread()
class Worker : public QObject
{
Q_OBJECT
private:
QThread* thread;
public:
void GoToThread() {
thread = new QThread();
this->moveToThread(thread);
}
void DoWork() {
//long work
}
};
Worker* w = new Worker();
w->GoToThread();
w->DoWork();
這段代碼到底會做什麼?它會把自己放到線程中嗎?我可以在外面打電話給DoWork()嗎?