我注意到当函数setModel http://doc.trolltech.com/4.0/qabstractitemview.html#setModel在并行线程中执行(我尝试了 threading.Timer 或 threading.thread),我得到这个:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QHeaderView(0x1c93ed0), parent's thread is QThread(0xb179c0), current thread is QThread(0x23dce38)
QObject::startTimer: timers cannot be started from another thread
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTreeView(0xc65060), parent's thread is QThread(0xb179c0), current thread is QThread(0x23dce38)
QObject::startTimer: timers cannot be started from another thread
有什么办法可以解决这个问题吗?
事实上,Qt(和其他丰富的框架)的多线程使用是一项微妙而困难的工作,需要明确的关注和照顾 - 请参阅Qt 的文档 https://doc.qt.io/qt-4.8/threads.html对这个主题进行了精彩的报道(对于有一般线程处理经验的读者,为那些还没有线程处理经验的读者提供了建议的阅读材料)。
如果可以的话,我会建议我一直建议的Python中最健全的线程架构:让每个子系统由一个专用线程拥有和使用;线程之间通过实例进行通信Queue.Queue
,即通过消息传递。这种方法可能有点限制,但它为专门识别和精心构建的异常提供了良好的基础(基于线程池、偶尔生成的新线程、锁、条件变量和其他此类挑剔的东西;-)。在后一类中,我还将对 Qt 特定的事物进行分类,例如通过排队连接 https://doc.qt.io/qt-4.8/threads-qobject.html#signals-and-slots-across-threads.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)