[Qt-interest] QAbstractItemModel, tree structure and dynamic datas
Tanguy Krotoff
tkrotoff at gmail.com
Sat May 2 19:17:09 CEST 2009
Hello
I can easily make my QAbstractItemModel be updated with new datas
dynamically when QAbstractItemModel is a simple list.
But I have some hard time to get this done with a tree structure like this one:
+ item1
- item11
- item12
(screenshot: http://www.ldc.usb.ve/docs/qt/images/windowsxp-treeview.png )
Here what I would like to achieve:
The user clicks on the "+" in front of item1:
- In another thread is done some computation
- When the computation is done, a signal computationDone(result) is sent
- The child items of item1 are getting added
To sum up, I would like to populate an item with its childs
dynamically using a different thread. Why? I want a responsive GUI and
the internal tree structure can be very big
Here what I have understood from the documentation, examples and mails
from this mailing-list:
- The "+" in front of item1 is showed when hasChildren() returns true
- When the user clicks on the "+", method canFetchMore() is being
called. If true is returned, it will call method fetchMore()
Here what I would like to implement inside my
QAbstractItemModel::fetchMore() method:
fetchMore(const QModelIndex & parent) {
computeInAnotherThread(parent);
//emits signal computationDone()
}
//Catches signal compuationDone()
slotComputationDoneFromOtherThread(const QStringList & childs) {
beginInsertRows(parent, first, last);
foreach (QString child, childs) {
//Change my internal tree data structure
}
endInsertRows();
}
Is it the right way to do it? Am I wrong about the use of
canFetchMore() and fetchMore()? Is there some examples/projects around
using QAbstractItemModel this way?
--
Tanguy Krotoff <tkrotoff at gmail.com>
+33 6 68 42 70 24
More information about the Qt-interest-old
mailing list