[Qt-interest] QAbstractItemModel, tree structure and dynamic datas
Girish Ramakrishnan
girish at forwardbias.in
Sun May 3 06:32:14 CEST 2009
Tanguy Krotoff wrote:
> 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();
> }
>
Look correct to me. What is the problem you are facing?
> 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?
>
4.5 has an example http://doc.trolltech.com/4.5/itemviews-fetchmore.html
Girish
More information about the Qt-interest-old
mailing list