Results 1 to 6 of 6

Thread: QStandardItem remove rows and row count

  1. #1
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default QStandardItem remove rows and row count

    After QStandardItem::removeRows() is called, the rowCount() returns the same number. How to completely eliminate rows?

  2. #2
    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: QStandardItem remove rows and row count

    Works fine for me:

    Qt Code:
    1. #include <QStandardItemModel>
    2. #include <QtDebug>
    3.  
    4. int main() {
    5. QStandardItemModel model(2,1);
    6. qDebug() << model.rowCount();
    7. model.removeRow(0);
    8. qDebug() << model.rowCount();
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Result:
    2
    1
    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.


  3. #3
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStandardItem remove rows and row count

    Thanks for reply
    I tried QStandardItem::removeRows() not QStandardItemModel::removeRow()

  4. #4
    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: QStandardItem remove rows and row count

    removeRow() calls removeRows() so this doesn't matter. Both will work.
    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.


  5. #5
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStandardItem remove rows and row count

    That was a typo, I missed "s" in second. What I mean is
    QStandardItem::removeRows() Vs QStandardItemModel::removeRows()
    The difference is class

  6. #6
    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: QStandardItem remove rows and row count

    QStandardItem::removeRows() can only fail if you provide an invalid index of the element to be removed. Otherwise it behaves the same as the model's method (it physically removes the row 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.


  7. The following user says thank you to wysota for this useful post:

    mqt (7th October 2013)

Similar Threads

  1. Remove selected rows from a QTableView
    By niko in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2016, 12:49
  2. Replies: 2
    Last Post: 14th May 2013, 13:20
  3. Deleting rows (children) from a qstandarditem
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 29th March 2012, 16:04
  4. Replies: 2
    Last Post: 15th August 2011, 00:26
  5. Count the number of rows in a QTableView
    By grub87 in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2009, 16:31

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.