Results 1 to 2 of 2

Thread: Table View not Updating after adding a new Row

  1. #1
    Join Date
    Jun 2019
    Location
    New Delhi
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Unhappy Table View not Updating after adding a new Row

    Hey Folks !

    Hope you all are doing well.

    I have been through a lot of similar links regarding the question but yet i didn't found any perfect solution regarding that. Here's my code :

    Qt Code:
    1. // Called this in constructor
    2. model = new QStandardItemModel(0,0,this);
    3.  
    4. // this is the logic of showing the view for Table View
    5. tableView = new QTableView(this);
    6. tableView->setModel(model);
    7. tableView->verticalHeader()->setVisible(false);
    8. tableView->verticalHeader()->setDefaultSectionSize(10);
    9.  
    10. for(int i = 0; i < clusterNames.length(); i++) {
    11. QStandardItem *clusterName_i = new QStandardItem(clusterNames[i]);
    12. QStandardItem *clusterIP_i = new QStandardItem(clusterIPs[i]);
    13.  
    14. model->setItem(i, 0, clusterName_i);
    15. model->setItem(i, 1, clusterIP_i);
    16. }
    17.  
    18. tableView->viewport()->update();
    To copy to clipboard, switch view to plain text mode 

    Logic/Explanation : The logic which i am doing behind this functionality as i populate a QDialog on a button and the data which i insert on the opened Dialog which is of different class. After adding the values i close that dialog and noticed that Tree & Table View aren't updating automatically but when i close that window and reopened it i saw it with updated values.

    If anyone have suggestions or the solution that would be a great help for me.

    Thanks In Advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Table View not Updating after adding a new Row

    The view should update automatically if the model changes.

    Maybe check if you are updating a different model than the one you are showing.

Similar Threads

  1. Replies: 3
    Last Post: 16th July 2015, 16:01
  2. Building Tree view from Table view which is already build.
    By DURGAPRASAD NEELAM in forum Newbie
    Replies: 6
    Last Post: 18th May 2015, 07:18
  3. Replies: 1
    Last Post: 8th June 2011, 14:13
  4. adding image to header column of a table view
    By nageshvk in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2011, 04:14
  5. Replies: 5
    Last Post: 3rd April 2010, 04:07

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.