[Qt-interest] QTreeView requests row == -1 in index function of model

Егор Попов faraslacks at gmail.com
Thu Sep 17 05:26:32 CEST 2009


Hi, everyone!

I have self-written model. It represents complex data structure. It's a tree
with tables on leaves.

Such that:

Root (TreeItem)
 |
 +-Section 1 (TreeItem)
 |
 +-Section 2 (TreeItem)
    |
    +-Factory (DataItem)
    |  |
    |  +-TableData (TableItem)
    |     |
    |     +- Cell Cell Cell (BaseItem)
    |     |
    |     +- Cell Cell Cell (BaseItem)
    |
    +-Factory (DataItem)

All vertices of tree stored in exemplar of class derived from BaseItem. In
index(), parent(), rowCount() etc. I do:

...
    BaseItem* item = static_cast<BaseItem*>(index.internalPointer);
    if (dynamic_cast<TreeItem*>(item)) {
        ...
    }

    if (dynamic_cast<TableItem*>(item)) {
        ...
    }

    if (dynamic_cast<BaseItem*>(item)) {
        ...
    }
...

to recognize what kind of item I have.

I think that rowCount() and columnCount() works right, but than I expand
"Section 2" branch of treeView QTreeView ask my index function for item with
row == -1.

P.S. Exuse me for my English.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090917/36addacf/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: projectModel.h
Type: application/octet-stream
Size: 5200 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090917/36addacf/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: projectModel.cpp
Type: application/octet-stream
Size: 18769 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090917/36addacf/attachment-0001.obj 


More information about the Qt-interest-old mailing list