Results 1 to 19 of 19

Thread: QTableView sort column with numbers very slow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QTableView sort column with numbers very slow

    My model was working wit a QStringList, each QString was a row, Name;Type;Company;etc... then i was using section() to get the data for each row cell. I've replaced the QStringList with QList<QStrngList>, i didn't know that section() were too slow, but with QList<QStringList> and using just MyListQSList.at(index.row()).at( column-nuber ) is very fast, just instantly:

    Qt Code:
    1. QVariant rs_GameModel::data(const QModelIndex &index, int role) const { //////////////////////////////////////////////////////////// DATA
    2. if (!index.isValid()) {
    3. return QVariant();
    4. }
    5. if (index.row() >= romCount || index.row() < 0 ) {
    6. return QVariant();
    7. }
    8.  
    9. if (role == Qt::TextAlignmentRole) {
    10. if (index.column() > 0 && index.column() < 10) {
    11. return Qt::AlignHCenter;
    12. }
    13.  
    14. }
    15. if (role == Qt::UserRole) {
    16. if (index.column() == 0) {
    17. return QString("%1;%2;%3").arg(ROMs.at(index.row()).at(12)).arg(ROMs.at(index.row()).at(14)).arg(ROMs.at(index.row()).at(15));
    18. }
    19. if (index.column() == 3) {
    20. ROMs.at(index.row()).at(11);
    21. }
    22.  
    23. }
    24. if (role == Qt::DecorationRole) {
    25. if (index.column() == 0) {
    26. return romicon;
    27. }
    28. if (index.column() == 2) {
    29. return QPixmap(QString("Skin/%1/icons/sys/rate%1.png").arg(CurrSkin));
    30. }
    31.  
    32. }
    33. if (role == Qt::DisplayRole) {
    34. if (index.column() == 0) {
    35. return ROMs.at(index.row()).at(0);
    36. }
    37. if (index.column() == 3) {
    38. if (ROMs.at(index.row()).at(3) != "rsnull") {
    39. return ROMs.at(index.row()).at(3);
    40. } else {
    41. return cEmulator;
    42. }
    43. }
    44. if (index.column() == 4) {
    45. return ROMs.at(index.row()).at(4);
    46. }
    47. if (index.column() == 5) {
    48. return ROMs.at(index.row()).at(5);
    49. }
    50. if (index.column() == 6) {
    51. return ROMs.at(index.row()).at(6);
    52. }
    53. if (index.column() == 7) {
    54. return ROMs.at(index.row()).at(7);
    55. }
    56. if (index.column() == 8) {
    57. return ROMs.at(index.row()).at(8);
    58. }
    59. if (index.column() == 9) {
    60. return ROMs.at(index.row()).at(9);
    61. }
    62. if (index.column() == 11) {
    63. return ROMs.at(index.row()).at(10);
    64. }
    65.  
    66. }
    67.  
    68. return QVariant();
    69. }
    To copy to clipboard, switch view to plain text mode 

    I suposse will discover what is fast and what is slow in qt with the time, and programmng wit it
    Always trying to learn >.<

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView sort column with numbers very slow

    Qt has nothing to do so. In every language search string section will take longer than getting the item from list or array.

Similar Threads

  1. How to sort QListWidget by numbers...
    By Patrick Sorcery in forum Newbie
    Replies: 7
    Last Post: 6th November 2017, 18:39
  2. How does the QTableWidget sort a column?
    By codemonkey in forum Qt Programming
    Replies: 1
    Last Post: 4th October 2009, 13:21
  3. how to SORT table of numbers with QT
    By tommy in forum Qt Programming
    Replies: 4
    Last Post: 29th May 2009, 09:34
  4. Replies: 2
    Last Post: 20th August 2008, 15:55
  5. Column with numbers
    By ederbs in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2006, 22:03

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.