开发环境: 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();
}

  

 

相关文章:

  • 2022-01-16
  • 2022-12-23
  • 2021-06-16
  • 2021-11-20
  • 2021-10-03
  • 2021-08-03
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-08-12
相关资源
相似解决方案