Results 1 to 9 of 9

Thread: Refresh TableModel

  1. #1
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Refresh TableModel

    I have been trying to get a tableview and table model to work at a reasonable speed lately and it has failed. If I add 100 rows it takes about 14 seconds to refresh the view and forget about trying to scroll...every time I use the scrollbar it lags, skipping lines all over the place.

    I tried to find what is taking so much of the systems resources, by putting qDebug()'s in my function and found that it calls the data() method continuously. It calls this method at least 5 times for each index and each role. Since I have 9 columns and there are seven roles it seems to call the method 31500 times then calls the header. It then starts over again without stopping. None of the data changes and I don't touch the screen while all this happening. It just keeps on calling data.

    I hope what I wrote made some sense. If you could help that would be great.
    My data method is something like this:
    Qt Code:
    1. QVarient class::data(const QModelIndex &index, int role) const
    2. {
    3. if(!index.isValid())
    4. return QVariant;
    5. if(role == Qt:AlignmentRole)
    6. return int(Qt::AlignRight | Qt::AlignVCenter);
    7. else if(role == Qt::DisplayRole)
    8. switch(index.column())
    9. {
    10. case 0: return 1;
    11. case 1: return 1;
    12. case 2: return 1;
    13. case 3: return 1;
    14. case 4: return 1;
    15. case 5: return 1;
    16. case 6: return 1;
    17. case 7: return 1;
    18. case 7: return 1;
    19. }
    20. }
    21. else
    22. return QVariant();
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 5th March 2008 at 16:20. Reason: missing [code] tags

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

    Default Re: Refresh TableModel

    First of all try adding more than one row at a time by introducing custom methods to the model.

  3. #3
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: Refresh TableModel

    I use
    Qt Code:
    1. beginInsertRows(row, count, QModelIndex)
    2. {
    3. then I populate my list
    4. }
    5. endInsertRows();
    To copy to clipboard, switch view to plain text mode 
    this way I can populate any number of rows
    Last edited by jpn; 8th March 2008 at 10:14. Reason: missing [code] tags

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

    Default Re: Refresh TableModel

    That's fine. Just make sure you don't call setData() afterwards I must say that with a model this size, your application should be very fast. So if you have a serveral seconds lag, you must be doing something wrong (either the model implementation is slow or you are using it in a slow way).

  5. #5
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: Refresh TableModel

    That is what I am thinking...I wish I could show you my code cause I am so stumped and so are my co-workers...but the code is not something I can show.

    I am never even created setData. The View isn't editable, the new items come from a message on the backend. When I put the debug in the code it never stops calling the Data method though...it keeps calling that and also the setHeaderData.

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

    Default Re: Refresh TableModel

    Maybe you can show us code similar to your original one, but simpler and working on some other data?

  7. #7
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: Refresh TableModel

    I don't think I have time to write one that will do this and not be the same thing, cause I am on such a deadline right now. I basically barely have time to finish this

  8. #8
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: Refresh TableModel

    Hey, Thank you guys for trying to help. I did find out what was slowing my view down.
    my data in my model were pointers in a list that was a pointer. So...

    QList< item *> * itemlist;

    I changed it to

    QList<item> itemlist;

    and it works fast

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

    Default Re: Refresh TableModel

    Hmm... really? Did it matter that much? I admit I'm surprised...

Similar Threads

  1. Refresh the Mainwindow at run time
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 15th November 2007, 13:16
  2. QTableView refresh
    By eleanor in forum Qt Programming
    Replies: 9
    Last Post: 6th October 2007, 18:00
  3. refresh form after adding a widget
    By cyrille in forum Newbie
    Replies: 2
    Last Post: 2nd February 2007, 10:40
  4. QTableView refresh problem
    By tebessum in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2006, 11:22
  5. Refresh QDataTable
    By shamik in forum Qt Programming
    Replies: 25
    Last Post: 1st December 2006, 05:04

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.