PDA

View Full Version : Filling QTreeWidget / Using QTreeView



stefanborries
15th April 2009, 14:53
I am not totally new to Qt but not as experienced as I like to be.

Thing is, I have a QTreeWidget and I want to add numerous QTreeWidgetItems to it.
This is rather timeconsuming and I don't want the app to freeze. So I thought about extracting the filling of the QTreeWidget to a seperate thread (which seems to be a bad idea). When running the programm averything works fine. Problem is I get the output:
'QObject::startTimer: timers cannot be started from another thread'.
Ok not so good. It's a warning and I want to take it serious.

I found that it is bad to interact with the QTreeWidget since it was created in another thread.

Short example:
ThreadA creates QTreeWidget.
ThreadB gets reference to QTreeWidget and adds QTreeWidgetItems. (This causes an output as mentioned above)
ThreadB resizes the columns of QTreeWidget. (Another output as mentioned above)

Would it be better to use QTreeView/QAbstractItemModel or something equal to do the trick?

Or should I step back from filling a QTreeWidget in a different thread?
I could get the data I need for filling the treewidget in a seperate thread and than use this data to fill the treewidget in the main thread.

Could I use a View/Model structure for this approach or would there be the same problem as I have right now?

Any hints will be appreciated.

stefanborries
15th April 2009, 16:25
Here I am again.

Think I found a solution to my problem.
I do the adding of the Treewidgets in the main thread and the collection of data in another thread.
When the collecting of data is finished a signal is emmited with all the QTreeWidgetItems in a QList. (QList<QTreeWidgetItem*>).
In the main thread a slot is called which gets the list and adds it to the QTreeWidget. (addTopLevelItems())

No output which should be of any concern.