Results 1 to 5 of 5

Thread: How to inform a QTableView about changes in the underlying QAbstractTablemodel?

  1. #1
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default How to inform a QTableView about changes in the underlying QAbstractTablemodel?

    Hi!

    I'm developing a customer library. I have a model and a view class:

    Qt Code:
    1. class CustomerLibrary : public QAbstractTableModel
    2. {
    3. //...
    4. public slots:
    5. void setSeachString (const QString & str){
    6. _vec_restricted.clear();
    7. foreach(Customer * c, _vec_all)
    8. if(c->contains(str)) _vec_restricted.append(c);
    9. }
    10. private:
    11. QVector<Customer*> _vec_all;
    12. QVector<Customer*> _vec_restricted;
    13. }
    14. class CustomerTableView : public QTableView
    15. {
    16. //...
    17. }
    To copy to clipboard, switch view to plain text mode 
    Ok, in order to find quickly an entry, I have a LineEdit whose textChanged signal is connected to the setSearchString(...) method.

    So anytime the text changes, drastic changes happen to my model.

    How can I inform the view that an update is necessary?
    Also I do not want to remove the rows one by one.

    Thnaks in advance,
    Olli

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?

    take a look at QAbstractItemModel::dataChanged() signal or maybe in your case QAbstractItemModel::reset() method would be better.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. The following user says thank you to faldzip for this useful post:

    olidem (6th May 2009)

  4. #3
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?

    Hi!

    Thanks for your reply.
    The questio I have is on what data the dataChanged signal refers.
    Lots of "rows" in my library can disappear and lots can appear.

    Eg if I had all entries before and now select only those containing the letter S, what shall I signal then? A dataChanged on all non-S-entires?

  5. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?

    if you insert rows or remove them there are signals for that: QAbstractItemModel::rowsInserted() and QAbstractItemModel::rowsRemoved(). And when you are for example inserting rows then you are emmiting rowsAboutToBeInserted then isert them and then emit rowsInserted. Please refer to Qt Examples & Demos and Qt Assistant, where whole item's change, insertion an removal is expalind clear.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #5
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?

    Thank you for your replies so far.

    I have (temporarily) solved the problem for now by simply calling QAbstractTabelModel::reset(). I will have to come back to this problem eventually later when dealing with more than a only few example customer datas.

    Thank you all!

Similar Threads

  1. Performance with QTableView and QAbstractTableModel
    By MBex in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2009, 08:04
  2. Replies: 3
    Last Post: 29th January 2009, 08:38

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.