Qt Labs Forum » ModelTest

QAbstractListModel and hasChildren()

(3 posts)

  1. mwerner
    mwerner
    Member

    Hej,

    I've subclassed QAbstractListModel() but not reimplemented hasChildren(). The test »Q_ASSERT(model->hasChildren(topIndex) == true);« in »ModelTest::rowCount()« fails and I don't quite get why.

    My rowCount() implementation looks like this:

    int MyModel::rowCount(const QModelIndex &parent) const
    {
    Q_UNUSED(parent);
    return entries->count();
    }

    entries is a QList<Entry>*.

    What am I getting wrong here?

    TIA,
    Max

    Posted: 1 year #
  2. Benjamin Meyer
    Benjamin Meyer
    Administrator

    You need to check if parent is valid or not. Because it is a list and not a tree the rowCount of any valid index would be 0. Because rowCount() is returning a positive number for a valid parent the modeltest is checking that hasChildren() with parent is also returning true.

    int MyModel::rowCount(const QModelIndex &parent) const
    {
    if (parent.isValid())
    return 0;
    return entries->count();
    }

    Posted: 1 year #
  3. mwerner
    mwerner
    Member

    Ok, now I got it! I shouldn't ignore parameters that airy. ;)

    Thx,
    Max

    Posted: 1 year #

RSS feed for this topic

Reply

You must log in to post.



© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.