2021-05-14 thread已经退出析构qtcreator中仍显示thread正在运行

threadobject已经析构,thread.isrunning 是false,thread.isfinishing() 也是true,说明thread退出了,但是qtcreator调试窗口中还是可见Qthread状态竟然是正在运行,什么鬼, 特此记录下这个现象。待解。

记录:sockect只能在同一个线程对象中使用.在同一个线程创建的变量也只能在当前线程使用。在实际运用中,切记不可跨线程去使用其他线程里面的变量等。若业务需求必须要使用其他线程的数据,可通过信号槽 将该数据emit出去,由其他线程接收再进行使用

//重写QTcpServer中的incomingConnection函数,当监听到有连接时,会调用此函数
void MyServer::incomingConnection(qintptr socketDescriptor)
{
    qDebug() << "主线程id:" << QThread::currentThread();
    Thread1 *thread = NULL;

    QMap<int, Thread1*>::iterator iter = m_mapThread.find(socketDescriptor);
    if(iter != m_mapThread.end())
        thread = iter.value();
    else
    {
        thread = new Thread1(socketDescriptor);
        m_mapThread[socketDescriptor] = thread;
    }

    //connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater()));//删除thread对象
    thread->start();
}

th
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值