首页 > 其他 > 详细

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

时间:2020-04-16 20:57:23      阅读:149      评论:0      收藏:0      [点我收藏+]

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

  

 

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

原文:https://www.cnblogs.com/Rainingday/p/12715069.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!