qt QTimer 提示 不能在另外一个线程停止

发送 信号 停止 timer 提示

QObject::killTimer: Timers cannot be stopped from another thread
QObject::~QObject: Timers cannot be stopped from another thread

启动时提示

QEventLoop: Cannot be used without QApplication

调试状态没有问题

发送信号量启动也没有问题

搞了半天查案看是

m_timer.moveToThread( &m_thread );
this->moveToThread( &m_thread );

尝试注释掉m_timer.moveToThread( &m_thread );或者this->moveToThread( &m_thread );

结果提示QObject::startTimer: Timers cannot be started from another thread

理论上注释掉m_timer.moveToThread( &m_thread ); timer还是在线程中运行的

后改位

this->moveToThread( &m_thread );//这个必须放到操作m_timer之前

connect(&m_timer, &QTimer::timeout, this, &InquiryProcess::OnTimeout ); m_timer.setSingleShot( true );
m_timer.moveToThread( &m_thread );

暂时解决
继续测试发现 有时还不能停止 停止槽函数不能进去

后改为直接使用线程 感觉时QTimer的bug

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

woquNOKIA

谢谢老板!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值