Qt Labs Forum » ModelTest

ModelTest and lazily populated models

(2 posts)
  • Started 1 year ago by Ralf
  • Latest reply from Benjamin Meyer

  1. Ralf
    Ralf
    Member

    I have a model that does not collect all its data at one time but rather lazily, i.e. when the data is actually needed.
    Therefore my hasChildren() method looks like that:

    
    bool MyTreeModel::hasChildren(const QModelIndex &parent) const
    {
        if (!parent.isValid())
    	{
    		return true;
    	}
    	else
    	{
    			MyTreeElement *parentItem = static_cast<MyTreeElement *>(parent.internalPointer());
    			if (parentItem->populated())
    			    return (parentItem->childCount() > 0);
    			else
    				return true;
    	}
    }
    

    This to my mind causes incorrect ASSERTs in ModelTest.cpp:310:

    
      // rowCount() and columnCount() said that it existed...
       Q_ASSERT(index.isValid() == true);
    

    Is it really a bug in the model or does ModelTest not work perfectly with a lazily popuplated model?

    Ralf

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

    That looks like a bug in your model. Line 310 simply tries to get every index that rowCount() and columnCount() said should exists. I would check the values of r and c to see if the test hit an edge case in the model.

    If a model says it has 10 rows and 8 columns then model->index(5,5).isValid() should be true.

    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.