Results 1 to 5 of 5

Thread: Removing row of a table.

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Removing row of a table.

    I am removing row from a table but all row of table are not delete.
    I am using this code

    Qt Code:
    1. for(int i=0; i<table.rowCount(); i++)
    2. table->removeRow(i);
    To copy to clipboard, switch view to plain text mode 

    Actually i want to delete all the rows of table. What is the way to do it.

    Guess I'm doing something wrong.
    Any help is appreciated,

  2. #2
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Removing row of a table.

    Try

    Qt Code:
    1. for(int i=table.rowCount()-1; i>=0; i--)
    2. table->removeRow(i);
    To copy to clipboard, switch view to plain text mode 

  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: Removing row of a table.

    Or
    Qt Code:
    1. table->clear();
    To copy to clipboard, switch view to plain text mode 
    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
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Removing row of a table.

    what nix said may be correct because each deleting of a row, all other row indexes are affected.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Removing row of a table.

    If you want to remove each row, one at a time (instead of calling clear()), you could do this:

    Qt Code:
    1. while ( table->rowCount() > 0 )
    2. table->removeRow( 0 );
    To copy to clipboard, switch view to plain text mode 

    Row 0 will always be a valid index as long as the table is not empty. Using a for() loop with rowCount() as a stopping condition will always get you in trouble because both the count and the for loop index are changing as you go through the loop.

Similar Threads

  1. Replies: 2
    Last Post: 21st March 2012, 14:30
  2. Replies: 1
    Last Post: 8th June 2011, 14:13
  3. Validator for the table widget item in table
    By mukunda in forum Qt Programming
    Replies: 4
    Last Post: 6th June 2011, 23:07
  4. Replies: 9
    Last Post: 21st June 2007, 10:27
  5. Removing rows from table model
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 20:36

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.