【Qt】Qt出现QObject: Cannot create children for a parent that is in a different thread.问题
来源:互联网 发布:淘宝英雄联盟 编辑:程序博客网 时间:2024/05/22 05:07
转: Qt出现QObject: Cannot create children for a parent that is in a different thread.问题
在Qt多线程变成里面,有时候会出现QObject: Cannot create children for a parent that is in a different thread.此类错误。说到底就是信号与槽分别处于主线程和从线程,信号与槽不在一个线程上。并且在Qt编程中又少不了信号与槽的关联,那么怎么解决这个问题了?我们可以这么做:
1、建立一个类,(假如这个类叫Demo:public QObject)继承于QObject,将这个类完整的表述,实现其功能;
2、然后建立一个指针QThread * thread = new QThread;
3、Demo *newDemo = new Demo;
newDemo->moveToThread(thread);
然后调用这个Demo类展开信号与槽链接,或者由其他信号启动这个类,
下来执行thread->start();
这样就把一个类放到一个单独线程中运行,而且根本不必重写run函数。
如果你需要多次调用这个类,那么只需要建立相应多的线程,将其moveto到这个线程就可以了。
这样信号与槽都会在这个建立的线程中运行,再也不会出现上述错误。
以上是自己开发中一点小技巧,欢迎批评指正!
阅读全文
0 0
- 【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.问题
- qt#5 QObject: Cannot create children for a parent that is in a different thread.
- Qt里出现 Cannot create children for a parent that is in a different thread
- QT线程出现错误Cannot create children for a parent that is in a different thread
- QObject: Cannot create children for a parent that is in a different thread
- QObject: Cannot create children for a parent that is in a different thread.
- QObject: Cannot create children for a parent that is in a different thread错误
- QObject: Cannot create children for a parent that is in a different thread.
- Qt中次线程里创建对象,出现Cannot create children for a parent that is in a different thread
- Qt中次线程里创建对象,出现Cannot create children for a parent that is in a different thread
- Cannot create children for a parent that is in a different thread
- Qt Tcp多线程下QObject:Can not create children that is in different thread 的解决方法
- QThread报错: Cannot create children for a parent that is
- QThread报错: Cannot create children for a parent that is
- ASSERT “Cannot send events to objects owned by a different thread.” SoQt Coin Qt
- What is a good parent-children rela
- Qt错误:QWidget: Cannot create a QWidget when no GUI is being used
- iOS 11 下适配UITableView 问题
- Secondary Namenode介绍
- LintCode刷题——数字三角形
- 1026. 程序运行时间(15)--Python
- Selenium自动化测试工具配置
- 【Qt】Qt出现QObject: Cannot create children for a parent that is in a different thread.问题
- Jquery表单序列化相关
- android 获取资源文件 r.drawable中的图片转换为drawable、bitmap
- android 蓝牙设备监听广播
- 使用sendmail发送email
- 【必须重视】人猝死前身体发出的2个救命信号,几十秒决定生死!
- 趣图 | 程序员最感到无助的时刻
- 明天就要上班了,这是我的心情...
- 扩展欧几里得及逆元模板