首页| 论坛| 消息

回复: Qt的多线程是不是不能使用QTimer
#11 [wcrqpdb 11-07 15:02]
zi.h
zu.h
main
zi.cpp
zu.cpp
报 QObject: Cannot create children for a parent that is in a different thread.
(Parent is zi(0x7cf9c0), parent's thread is QThread(0x176f60), current thread is zi(0x7cf9c0)
原程序
#12 [圣域天子 11-07 16:35]
QTimer 在线程中不要用 new
QTimer k; 就可以了。run结束后它自动释放。
不过 k 如果关联信号的话,应该依旧会存在。
你的需求的实现方式应该调整一下,在线程中使用 QTimer 发时间信号,应该是没意义了。
#13 回 圣域天子 的帖子 [wcrqpdb 11-07 18:02]
圣域天子:QTimer 在线程中不要用 new
QTimer k; 就可以了。run结束后它自动释放。
不过 k 如果关联信号的话,应该依旧会存在。
....... (2019-11-07 16:35) 
我要定时处理数据
#14 回 wcrqpdb 的帖子 [dbzhang800 11-07 19:00]
wcrqpdb:zi.h
zu.h
main
....... (2019-11-07 15:02) 
你在run()内写下列代码,错了。run()函数内是次线程,但是this不在次线程内,不能作为父对象。
new QTimer(this)
另外,run() 内没有 exec()函数,只把timer创建放到run内也没有意义,你代码中的槽函数又不在你的run内执行
#15 回 dbzhang800 的帖子 [wcrqpdb 11-07 19:38]
dbzhang800:你在run()内写下列代码,错了。run()函数内是次线程,但是this不在次线程内,不能作为父对象。
new QTimer(this)
另外,run() 内没有 exec()函数,只把timer创建放到run内也没有意义,你代码中的槽函数又不在你的run内执行 (2019-11-07 19:00)
要怎么写,麻烦写一下,上面有原程序

<< 1 2 3 4 5 >> (3/7)

回复 发表
主题 版块