Results 1 to 4 of 4

Thread: Performance problems with subclassed QAbstractItemModel

  1. #1
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Performance problems with subclassed QAbstractItemModel

    I have created my own data model derived from QAbstractItemModel. The model is used to store communication trace data row by row. A row holds the data of an inbound or outbound packed. The packet's information is split across different columns such as 'Timestampt', 'Source', 'Destination' etc. The row buffer has a configurable size and if it gets full the oldest row (the first in the model) is discarded and the new row gets appended (as last row). To display the data I use QTreeView.

    Things are working fine but the performance is poor. When I use more then 10 rows scrolling is very slow and the processor load is somewhere between 35% to 80%!

    My data model implements the following methods from QAbstractItemModel:
    - columnCount
    - rowCount
    - index
    - parent
    - data;
    - headerData

    My own method 'AppendRow' to add a row of trace information uses 'beginInsertRows' and 'endInsertRows' to do the job.

    I am pretty sure that I missed something very important in my implementation of the sublassed QAbstractItemModel but I just can't imagine what and where the performance lost comes from. Using gprof I found that the method 'data' uses up most of the time but I think this is quite logic and correct as it is the method called over and over again from the view to get information about what to display, right?
    So, what did I really miss? Can anybody give me a hint?

    Many thanks Felix

  2. #2
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Performance problems with subclassed QAbstractItemModel

    I have used 'ModelTest' from http://labs.trolltech.com/page/Proje...view/Modeltest, hoping it could give me some hint. It is a good tool but it did not help with the performance problem.

    I somehow feel that when I append an item at the end of my list everything (all items) get reordered by the view and that this could be the problem. Years ago we wrote a Windows application which is also able to trace communication; this application is still running and it's performance is excellent, no matter how long (how many lines) the trace buffer has. Only problem: it is programmed for Windows so it is not portable.

    Is there really nobody who could push me in the right direction? Is there eventually somewhat like 'ModelTest' that could analyze errors which result in bad performance?

  3. #3
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Performance problems with subclassed QAbstractItemModel

    Some more information:

    During debugging I found Qt call my model's data member for each column and each row every time I append a row. It does this no matter how many rows are visible in the view, i.e. if my data model has 500 rows and 30 rows are visible the view requests all data including the data for the 470 rows that are not visible. No wonder everything is getting very slow and the CPU load increases.
    What I do net yet know is how to solve this problem since I do not seem to understand how the view decides about which data it should request from the model.

  4. #4
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Performance problems with subclassed QAbstractItemModel

    Are you using "emit dataChanged(QModelIndex& topLeft, QModelIndex& bottomRight)"?

    See:
    http://doc.qt.nokia.com/latest/qabst...ml#dataChanged

    This signal should be emitted whenever your data changes. The arguments tell your view which data members should be updated. I believe your view will only call "data" on the cells between the ones you specify and only when you emit this signal. Maybe you are emitting the signal too often, or including too much of your list. Try narrowing your topLeft and bottomRight to only surround the ones that you changed.

    I'm actually having some performance issues with this as well. Does anyone know of a general way to speed this up, or something faster than the QAbstractTableModel/QTableView?

Similar Threads

  1. Performance problems playing video with Phonon and GStreamer on QT Embedded.
    By MarcosRodriguez in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd December 2009, 13:57
  2. Performance problems with small pixmap
    By RThaden in forum Qt Programming
    Replies: 4
    Last Post: 9th July 2008, 15:14
  3. Performance problems with overlapping qgraphicsitems
    By brjames in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 21:42
  4. QGraphicsScene/QGraphicsView performance problems
    By bnilsson in forum Qt Programming
    Replies: 71
    Last Post: 28th January 2008, 12:08
  5. GraphicsView performance problems
    By Gopala Krishna in forum Qt Programming
    Replies: 79
    Last Post: 8th August 2007, 17:32

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.