0
点赞
收藏
分享

微信扫一扫

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 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​​
  • ​​摘要​​
  • ​​1 问题分析​​
  • ​​2 解决问题​​


关键字:

​关键字1​​、

​关键字2​​、

​关键字3​​、

​关键字4​​、

​关键字5​

内容背景:

最近项目终于切到Linux下开发了,所以最近的记录都是发生在​​Debian 10​​​ 以及​​Arm Debain 10​​​ 下,​​Qt​​​版本​​5.12.3​​。这几天真是问题多多,收获满满,不过目前阶段仅仅停留在解决问题,至于原理性的东西,还得慢慢消化。最近好多问题都是直接群里问大神,感谢各位大神助我成长。

摘要

今天在搞代码的时候,触发了新的不问题,也不是BUG,就是在控制台有红色的日志输出,红色,那应该就是比较重要的内容了,所以要重点照顾一下。报错内容如下

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_02

1 问题分析

这句这外国语言描述,就是​​无法为不同线程中的父级创建子级​​,说了个寂寞,结合代码来看你,其实就是我有一个线程,在线程里面用到一个变量吧,这个变量其实是在主线程中创建的,子线程中虽然可以使用,但是其实还是操作的主线程的对象。就是这个意思,结合代码,这个就是我自己写的一个音频类里面。我使用了movetoThread的方式,所以我在线程的构造函数里面创建了变量,但是你,在我线程构造函数调用的时候,其实线程还没有创建。所以就有了子线程调用主线的问题,就出现了这共色的内容。

2 解决问题

知道了问题在哪里,就很好解决,那就把变量放在线程里面分配资源就好, 如下,把它送构造函数移动到线程启动槽函数里面就可以

Qt QObject Cannot create children for a parent that is in a different thread_children_03

举报

相关推荐

0 条评论