error: must use ‘class’ tag to refer to type ‘XXX’ in this scope


開發環境: 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();
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM