Results 1 to 3 of 3

Thread: How to make QTableView aware that a new item in the model has beed aded?

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to make QTableView aware that a new item in the model has beed aded?

    Hi,

    So I have a QTableView using my model based on QAbstractTableModel. My model loads items from a file and stores them in a QList. I have a function called addItem(QString code, QString description) that appends a new item at the end of the QList..

    rowCount() returns my_items.count();

    I also implemented data() so it properly shows the current items in the file.

    Now, what do I need to do so the view shows the new item?

    Thanks,
    Carlos.

  2. #2
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to make QTableView aware that a new item in the model has beed aded?

    Implement in your model public function that calls QAbstractItemModel::reset(),then invoke it

  3. #3
    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: How to make QTableView aware that a new item in the model has beed aded?

    Take a look to
    Qt Code:
    1. void QAbstractItemModel::layoutChanged ()
    To copy to clipboard, switch view to plain text mode 
    , you have to emit this signal and then the view will know and refresh itself about the change.
    Last edited by nix; 12th August 2011 at 15:07. Reason: typo

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 19:39
  2. Using model indices in complex model item relationships
    By hackerNovitiate in forum Newbie
    Replies: 0
    Last Post: 29th June 2011, 14:30
  3. Qt Creator How to make Creator be aware of the Qt source code project?
    By kartwall in forum Qt Tools
    Replies: 5
    Last Post: 27th September 2010, 08:39
  4. Replies: 1
    Last Post: 1st February 2010, 18:42
  5. QTableView::sortByColumn locale-aware sorting
    By Matriarch in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2010, 16:21

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.