This forum has been archived. All content is frozen. Please use KDE Discuss instead.

QModelIndex() is valid?

Tags: None
(comma "," separated)
K4m1K4tz3
Registered Member
Posts
35
Karma
0

QModelIndex() is valid?

Thu May 07, 2009 5:21 pm
Hi, it's me again with a new question.

I reimplemented the QAbstractItemModel here is a part of the code:

Code: Select all
QModelIndex BookmarkModel::index(int row, int column, const QModelIndex &parent) const
{
    if (!hasIndex(row, column, parent)) {
        return QModelIndex();
    }

    TreeItem *parentItem;

    if (!parent.isValid()) {
        //it doesn't reach this point
        parentItem = trueParents.first();
    } else
        parentItem = static_cast(parent.internalPointer());

    TreeItem *childItem = parentItem->child(row);
    if (childItem)
        return createIndex(row, column, childItem);
    else
        return QModelIndex();
}


I call this function with this code:

QModelIndex trueParentWithChangedChild = index(0, 0, QModelIndex());


If I call index(0, 0, QModelIndex()) it should give me a pointer to the first entry in my QList: trueParents.first()

But it doesn't.

if (!parent.isValid())

This is answered with no, so this means that QModelIndex() is valid. But why is it valid? I don't understand.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

RE: QModelIndex() is valid?

Fri May 08, 2009 5:46 am
It works with the MenuModel used in System Settings. ( code at websvn.kde.org/trunk/KDE/kdebase/workspace/systemsettings/core/ in MenuModel.cpp )

Try starting with negative numbers instead of "0"'s.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]