Results 1 to 13 of 13

Thread: How to display periodically updated data in QTableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    315
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanked 53 Times in 51 Posts

    Default Re: How to display periodically updated data in QTableView

    If you are lazy and dont care about perfomance you can use QAbstractItemModel::beginResetModel and QAbstractItemModel::endResetModel.
    If you are just changing some values then emit signal: QAbstractItemModel::dataChanged.

  2. #2
    Join Date
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display periodically updated data in QTableView

    I am lazy, because it cost 10 ms for 100 rows to delete and insert. I found the answer in a brainstorming session last night.

    My mistake was simple. I have not cleaned the data before I save new.

    This is my code for others:

    Qt Code:
    1. void TxTableModel::parseXml(const QByteArray &xml)
    2. {
    3. QXmlInputSource inputSource;
    4. TxSaxTableHandler handler(&m_Data, false);
    5.  
    6. inputSource.setData(xml);
    7. reader.setContentHandler(&handler);
    8. reader.setErrorHandler(&handler);
    9.  
    10. QModelIndexList selectedList = parent->selectionModel()->selectedRows();
    11.  
    12. beginResetModel();
    13. m_Data.clearData();
    14. reader.parse(inputSource);
    15. endResetModel();
    16.  
    17. for( int i=0; i<selectedList.count(); i++) {
    18. parent->selectRow(selectedList.at(i).row());
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to display periodically updated data in QTableView

    Just be aware that if you reset the model, you'll lose the selection and positioning in all the views attached to 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.


  4. #4
    Join Date
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display periodically updated data in QTableView

    I can already see it. Is there any way to restore the scroll?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to display periodically updated data in QTableView

    Don't reset 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.


  6. #6
    Join Date
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display periodically updated data in QTableView

    I cant. Line change so often that it is much easier to reset the entire model than to merge

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to display periodically updated data in QTableView

    Quote Originally Posted by nickla View Post
    I cant. Line change so often that it is much easier to reset the entire model than to merge
    Then you won't retain scrolling and selection. Simple as that. It's either easy or effective, the choice is yours.
    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.


  8. #8
    Join Date
    Dec 2009
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: How to display periodically updated data in QTableView

    I had a similar problem and even tried to retain unique data from each selected itens before modelReset and then, after modelReset I tried to search for the data in then new model and finaly select the respective position at the view. Did not work or I was doing something really wrong. I finally surrendered to the model merging process. It is working like a charm but model merging took me a while to figure out!

  9. #9
    Join Date
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display periodically updated data in QTableView

    This is my NonMerge method:

    Qt Code:
    1. void TxTableModel::parseXml(const QByteArray &xml)
    2. {
    3. QXmlInputSource inputSource;
    4. TxSaxTableHandler handler(&m_Data, false);
    5.  
    6. inputSource.setData(xml);
    7. reader.setContentHandler(&handler);
    8. reader.setErrorHandler(&handler);
    9.  
    10. QModelIndexList selectedList = parent->selectionModel()->selectedRows();
    11. QModelIndex scrollTopIndex = parent->indexAt(QPoint(1, 1));
    12. QModelIndex scrollBottomIndex = parent->indexAt(QPoint(1, parent->height() - 1));
    13.  
    14. beginResetModel();
    15. m_Data.clearData();
    16. reader.parse(inputSource);
    17. endResetModel();
    18.  
    19. if (scrollBottomIndex.row() == -1) {
    20. parent->scrollToBottom();
    21. } else {
    22. parent->scrollTo(scrollTopIndex);
    23. }
    24.  
    25. if (selectedList.count() > 0 && (selectedList.at(0).row() >= scrollTopIndex.row()) && (scrollBottomIndex.row() == -1 || scrollBottomIndex.row() > selectedList.at(0).row() )) {
    26. parent->selectRow(selectedList.at(0).row());
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    But I really hope that you would not use this. It makes me a lot of pain to support (edit cell is something terrible) and I`m working on merge too.

Similar Threads

  1. Display DIB data
    By nightroad in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2010, 21:42
  2. Replies: 1
    Last Post: 23rd September 2010, 20:16
  3. QTableview data display font question
    By MarkoSan in forum Newbie
    Replies: 8
    Last Post: 14th May 2008, 12:57
  4. Replies: 5
    Last Post: 29th January 2008, 17:36

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
  •  
Qt is a trademark of The Qt Company.