Results 1 to 4 of 4

Thread: Problem in own model (modeltest fail)

  1. #1
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem in own model (modeltest fail)

    Hello,

    I'm testing my model with qt modeltest but two tests fail: rowsInserted and rowsRemoved.

    This is the method to delete an item:
    Qt Code:
    1. void UserModel::delItem(const QString &nick)
    2. {
    3. int row = findItem(nick);
    4. qDebug() << "Going to remove " << nick;
    5. if(row < 0) {
    6. qDebug() << "No item found with nick " << nick;
    7. return;
    8. }
    9. UserItem *u = userList[row];
    10. beginRemoveRows(QModelIndex(), row, row);
    11. qDebug() << "Item " << u->nick << " removed";
    12. userList.removeAt(row);
    13. delete u;
    14. qDebug() << "Really removed? " << (findUser(nick) < 0 ? "Yes" : "No!");
    15. endRemoveRows();
    16. }
    To copy to clipboard, switch view to plain text mode 

    I have added more debug to modeltest.cpp and here the result:

    Going to remove "foobar"
    User "foobar" removed
    Really removed? Yes
    rowsRemoved start= 41 end= 41 oldsize= 192 parent= "" current rowcount= 192
    isIndexValid No
    itemWasRemoved: QVariant(, )
    ASSERT: "c.oldSize - (end - start + 1) == model->rowCount(parent)" in file ./modeltest/modeltest.cpp, line 537
    The item is really removed from userList (QList<UserItem *>) but the value returned by rowCount() doesn't reflect the change. rowCount() implementaion is ok:
    Qt Code:
    1. int UserModel::rowCount(const QModelIndex &parent) const
    2. {
    3. return parent.isValid() ? 0 : userList.count();
    4. }
    To copy to clipboard, switch view to plain text mode 

    Any idea? Thx

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem in own model (modeltest fail)

    After deletion, update the view. Better use:
    Qt Code:
    1. bool QAbstractItemModel::removeRow ( int row, const QModelIndex & parent = QModelIndex() )
    To copy to clipboard, switch view to plain text mode 
    Last edited by yogeshgokul; 30th July 2009 at 09:41.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in own model (modeltest fail)

    rowsInserted and rowsRemoved will fail if you didn't reimplement appropriate methods from the model..
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in own model (modeltest fail)

    So your suggestion is to implement removeRows and insertRow instead of own methods?

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. model View programming problem
    By mismael85 in forum Qt Programming
    Replies: 3
    Last Post: 2nd April 2008, 21:44
  3. tableview model view problem
    By skuda in forum Qt Programming
    Replies: 5
    Last Post: 3rd December 2007, 14:02
  4. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45
  5. Relational Table Model Problem
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2007, 14:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.