一个疑惑的问题:QObject::killTimer: Timers cannot be stopped from another thread
来源:互联网 发布:js contents 编辑:程序博客网 时间:2024/05/21 19:32
QObject的connect函数有几种连接方式,
a) DirectConnection,信号发送后槽函数立即执行,由sender的所在线程执行;
b) QueuedConnection,信号发送后返回,相关槽函数由receiver所在的线程在返回到事件循环后执行;
c)默认使用的是Qt::AutoConnection,当sender和receiver在同一个线程内时,采用DirectConnection的方式,当sender和receiver在不同的线程时,采用QueuedConnection的方式。
MySerialPort::MySerialPort()
:m_pThread(newQThread()),
m_pCom(newQSerialPort())
{
m_pCom->moveToThread(m_pThread);
this->moveToThread(m_pThread);
m_pThread->start();
connect(m_pCom,&QSerialPort::readyRead,this,&MySerialPort::slotDataReady);
connect(this,&MySerialPort::sigSetCOM,this,&MySerialPort::slotSetCOM);
//下面的slot在sender(即resendCheckTimer)所在线程执行
connect(&resendCheckTimer,SIGNAL(timeout()),this,SLOT(slotResendProcess()),Qt::DirectConnection);
}
voidMySerialPort::slotResendProcess()
{
resendCheckTimer.stop();
}
1. 第一种情况即上述方式
打印信息:
main thread------------------------- QThread(0x11918c0)
MySerialPort::slotDataReady()------------------: 0x3084
MySerialPort::slotResendProcess----------------:0x2f20
2.第二种情况
改为:
connect(&resendCheckTimer,SIGNAL(timeout()),this,SLOT(slotResendProcess()));//slot默认会在receiver(即this)所在线程执行
打印信息:
main thread------------------------- QThread(0x126918c0)
MySerialPort::slotDataReady()------------------: 0x2db8 //this所在线程
MySerialPort::slotResendProcess----------------:0x2db8 //this所在线程
QObject::killTimer: Timers cannot be stopped from another thread
注意:最下面一条警告,执行resendCheckTimer.stop()报错了,说明在第一种情况下(Qt::DirectConnection),槽函数会在receiver(即this)所在线程跟sender(即resendCheckTimer)所在线程不一致,且sender所在线程和主线程、次线程都不是一个线程,有点不明白了。。。。
- 一个疑惑的问题:QObject::killTimer: Timers cannot be stopped from another thread
- [pyQt_Error]QObject::killTimer: timers cannot be stopped from another thread
- ORB-SLAM2:QObject::~QObject: Timers cannot be stopped from another thread
- QT中解决QSocketNotifier: socket notifiers cannot be enabled from another thread错误
- QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
- Server Timers, Windows Timers, and Thread Timers的对比
- SetTimer 和 KillTimer 打开一个模态对话框的问题
- QObject的Thread Affinity翻译
- 自己一个疑惑的问题
- 百钱百鸡问题的一个疑惑
- paip. 'QObject::QObject(const QObject&)' is private问题的解决.
- 【Qt】Qt出现QObject: Cannot create children for a parent that is in a different thread.问题
- 【Qt】Qt出现QObject: Cannot create children for a parent that is in a different thread.问题
- 解决'libproxychains.so.3' from LD_PRELOAD cannot be preloaded问题
- 有关timers的延时问题
- 关于ManagementFactory cannot be resolved的问题!
- QObject 之 Thread Affinity
- QObject 之 Thread Affinity
- android studio so文件打包
- 八皇后问题 java
- 【Javascript】三个常用输出语句
- 自主车辆相关资源
- Java String、StringBuffer和StringBuilder类的区别
- 一个疑惑的问题:QObject::killTimer: Timers cannot be stopped from another thread
- python中的unicode
- 静态库和动态库
- 查询时候自己加个自增列
- 百练之小数的进制转换
- FTP服务
- 嵌入式开发中DSP与FPGA的关系
- RN学习之我的第一个RN小例子
- 连续输入密码错误3次,第二天才能登录