简体   繁体   English

QTreeWidget 填充从线程 Item 展开

[英]QTreeWidget fill from thread Item expanded

I fill my QTreeWidget out of a thread.我用一个线程填充了我的 QTreeWidget。 Works well so far, but after he data is populated, all items are not expanded but they are available.到目前为止运行良好,但在填充数据后,所有项目都没有展开,但它们可用。 All items I added I set ...setExpanded(true);我添加的所有项目我都设置了...setExpanded(true);

This cause at the end the problem, that treeCount() is 1.这最终导致了问题,即treeCount()为 1。

I want to avoid to set in constructer expandAll and I also want to avoid to make an extra List to count the items.我想避免在构造函数expandAll设置,我也想避免创建一个额外的 List 来计算项目。

If I start the fill method from common app thread as a simple function, everything I ...setExpanded(true);如果我从普通应用程序线程中将 fill 方法作为一个简单的函数启动,那么我...setExpanded(true); is expanded after populate.填充后扩展。

I there a trick to avoid this problem?我有避免这个问题的技巧吗?

Never mangle with a QObject from a different thread.永远不要使用来自不同线程的 QObject。 All GUI object operations need to be done in the same thread.所有 GUI 对象操作都需要在同一个线程中完成。

Use a signal/slot mechanism between your threads to communicate new items.在线程之间使用信号/插槽机制来传达新项目。 Alternatively, set up a new Q*ItemModel in the extra thread and pass it once in a signal.或者,在额外的线程中设置一个新的 Q*ItemModel 并在信号中传递一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM