開發環境: Qt Creator 4.11.0
在寫程序的時候,遇到了編譯器報錯 error: must use 'class' tag to refer to type 'thread' in this scope
void Server::incomingConnection(int socketDescriptor) { thread *h = new thread(socketDescriptor); connect(h,&thread::isFinished,h,&thread::deleteLater);//當線程完成后,釋放內存 h->start(); }
thread是我定義的一個類(線程),查找原因發現,thread是QObject類的一個函數,所以需要指明是是一個類。
QThread *QObject::thread() const
修改如下:
void Server::incomingConnection(int socketDescriptor) { class thread *h = new class thread(socketDescriptor); connect(h,&thread::isFinished,h,&thread::deleteLater);//當線程完成后,釋放內存 h->start(); }