Results 1 to 3 of 3

Thread: QSortFilterProxyModel and QTableView problem.

  1. #1
    Join Date
    May 2013
    Posts
    2
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question QSortFilterProxyModel and QTableView problem.

    Hi there,

    I am developing a program that gets data from a CAN bus interface and presents the data in a QTableView.

    The program receives about 600 messages per second, sometimes more and it all works beautifully. QTableView is easily able to keep up with all the new rows being added.

    Now to my problem.

    I have encountered a problem when trying to use QSortFilterProxyModel to filter the data presented to the user.

    At first i tried to filter on the value of a column and it worked for a very short while, about 2 seconds before the program just locked up.

    After that i tried to just connect the proxymodel to the model and the view without doing any filtering. Now the program works for about ten seconds before slowing to a crawl and then locking up once again.

    I connect the proxy model like this:
    Qt Code:
    1. m_pcanTableProxyModel = new QSortFilterProxyModel(this);
    2. ui->canTableView->setModel(m_pcanTableProxyModel);
    3. m_pcanTableProxyModel->setSourceModel(m_pcanTableModel);
    To copy to clipboard, switch view to plain text mode 

    The other relevant piece of code I can think of is the data function of my model class:

    Qt Code:
    1. QVariant CanTableModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (role != Qt::DisplayRole)
    4. {
    5. return QVariant::Invalid;
    6. }
    7.  
    8. switch (index.column())
    9. {
    10. case CanMessage::Time:
    11. if (m_timeFlag == 0)
    12. {
    13. return QString::number(m_pcanMessageHandler->getMessage(index.row()).getSeconds());
    14. }
    15. else // relative time
    16. {
    17. return m_pcanMessageHandler->getRelativeTime(index.row());
    18. }
    19. break;
    20. case CanMessage::Status:
    21. return m_pcanMessageHandler->getMessage(index.row()).getStatus();
    22. break;
    23. case CanMessage::CanID:
    24. if (m_hexIdFlag == 1)
    25. {
    26. return QString::number(m_pcanMessageHandler->getMessage(index.row()).getId(),16);
    27. }
    28. else
    29. {
    30. return m_pcanMessageHandler->getMessage(index.row()).getId();
    31. }
    32. break;
    33. case CanMessage::CFC:
    34. if (m_cfcFlag == 1)
    35. {
    36. if (index.model()->data(index.model()->index(index.row(), 4)) == 0)
    37. {
    38. return QString::fromStdString(m_cfcTable.getBroadcastString(m_pcanMessageHandler->getMessage(index.row()).getCfc()));
    39. }
    40. else
    41. {
    42. return QString::fromStdString(m_cfcTable.getPeerToPeerString(m_pcanMessageHandler->getMessage(index.row()).getCfc()));
    43. }
    44. }
    45. else
    46. {
    47. return m_pcanMessageHandler->getMessage(index.row()).getCfc();
    48. }
    49. break;
    50. case CanMessage::Module:
    51. return m_pcanMessageHandler->getMessage(index.row()).getModule();
    52. break;
    53. case CanMessage::Length:
    54. return m_pcanMessageHandler->getMessage(index.row()).getLength();
    55. break;
    56. case CanMessage::Data:
    57. if (m_hexDataFlag == 1)
    58. {
    59. return QString::fromStdString(m_pcanMessageHandler->getMessage(index.row()).getDataString(true));
    60. }
    61. else
    62. {
    63. return QString::fromStdString(m_pcanMessageHandler->getMessage(index.row()).getDataString(false));
    64. }
    65. break;
    66. }
    67.  
    68. return QVariant::Invalid;
    69. }
    To copy to clipboard, switch view to plain text mode 

    Anyone able to help me with this? It's driving me slightly mad.

  2. The following user says thank you to Thule for this useful post:


  3. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QSortFilterProxyModel and QTableView problem.

    Where is stack pointer when the program gets locked up / unresponsive. Try to stop the debugger and see where it is stuck !
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  4. The following user says thank you to Santosh Reddy for this useful post:


  5. #3
    Join Date
    May 2013
    Posts
    2
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QSortFilterProxyModel and QTableView problem.

    Quote Originally Posted by Santosh Reddy View Post
    Where is stack pointer when the program gets locked up / unresponsive. Try to stop the debugger and see where it is stuck !
    I tried to debug the application but it seems it isn't really locked up, it still continues to collect data. It seems it just doesn't have the time to update the user interface.

    Looks like I will just have to find another way to do this without QSortFilterProxyModel since it seems to be too slow for the amount of data the program needs to collect and show.

Similar Threads

  1. Replies: 3
    Last Post: 20th April 2014, 21:49
  2. QTableView with QSortFilterProxyModel
    By TheGrimace in forum Qt Programming
    Replies: 4
    Last Post: 13th November 2012, 16:38
  3. Problem with QTableView and QSortFilterProxyModel
    By unix7777 in forum Qt Programming
    Replies: 7
    Last Post: 24th August 2012, 09:11
  4. Moving Items in QTableView with QSortFilterProxyModel
    By Rudolf Rendier in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2012, 16:07
  5. Replies: 6
    Last Post: 22nd November 2011, 04:53

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.