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
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    4

    Default Re: QTableView sort column with numbers very slow

    It's strange, but the table still has sorting speed problems, whe all columns values are setted, i can take 5 seconds to sort by column. There is not ini access in the model.
    Where could be the problem? i'm using a QSortFilterProxyModel too.

    I really need solve the QTableView problems, its the central widget of my app, and can't have a good perfomance with 8000+ rows. I've seen an app that make all this REALLY instantly (coded in Delphi), i need to have that perfomance, if not, my app becomes useless in comparission .
    This table is going to kill me

    Here is my data implementation just now (note i've commented the DecorativeRole part to check if that helps to speed, but no luck, still slow):

    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.  
    18. return QString("%1;%2;%3").arg(ROMs.at(index.row()).section(";", 12, 12)).arg(ROMs.at(index.row()).section(";", 14, 14)).arg(ROMs.at(index.row()).section(";", 15, 15));
    19. }
    20. if (index.column() == 1) {
    21. return ROMs.at(index.row()).section(";", 1, 1);
    22. }
    23. if (index.column() == 2) {
    24. return ROMs.at(index.row()).section(";", 2, 2);
    25. }
    26. if (index.column() == 3) {
    27. return ROMs.at(index.row()).section(";", 11, 11);
    28. }
    29. }
    30. // if (role == Qt::DecorationRole) {
    31. // if (index.column() == 0) {
    32. // return romicon;
    33. // }
    34. // if (index.column() == 1) {
    35. // QString tmpExt = ROMs.at(index.row()).section(";", 1, 1);
    36.  
    37. // if (tmpExt.compare("zip", Qt::CaseInsensitive) == 0 || tmpExt.compare("7Z", Qt::CaseInsensitive) == 0 || tmpExt.compare("r", Qt::CaseInsensitive) == 0 ) {
    38. // return QIcon(QString("Skin/%1/icons/sys/compressed16.png").arg(CurrSkin));
    39. // } else if (tmpExt.compare("iso", Qt::CaseInsensitive) == 0 || tmpExt.compare("cue", Qt::CaseInsensitive) == 0 || tmpExt.compare("bin", Qt::CaseInsensitive) == 0 ||
    40. // tmpExt.compare("nrg", Qt::CaseInsensitive) == 0 || tmpExt.compare("mdf", Qt::CaseInsensitive) == 0 || tmpExt.compare("mds", Qt::CaseInsensitive) == 0 ) {
    41. // return QIcon(QString("Skin/%1/icons/sys/cddvd16.png").arg(CurrSkin));
    42. // } else {
    43. // return QIcon(QString("Skin/%1/icons/sys/cartridge16.png").arg(CurrSkin));
    44. // }
    45. // }
    46.  
    47. // if (index.column() == 2) {
    48. // if (ROMs.at(index.row()).section(";", 2, 2).toInt() != 0) {
    49. // return QPixmap(QString("Skin/%1/icons/sys/rate%2.png").arg(CurrSkin).arg(ROMs.at(index.row()).section(";", 2, 2).toInt()));
    50. // }
    51. // }
    52. // }
    53. if (role == Qt::DisplayRole) {
    54. if (index.column() == 0) {
    55. return ROMs.at(index.row()).section(";", 0, 0);
    56. }
    57.  
    58. if (index.column() == 3) {
    59. if (ROMs.at(index.row()).section(";", 3,3) == "rsnull") {
    60. return cEmulator;
    61. } else {
    62. return ROMs.at(index.row()).section(";", 3,3); }
    63. }
    64. if (index.column() == 4) {
    65. return ROMs.at(index.row()).section(";", 4, 4);
    66. }
    67. if (index.column() == 5) {
    68.  
    69. return ROMs.at(index.row()).section(";", 5, 5).replace("rsnull", "");
    70.  
    71. }
    72. if (index.column() == 6 ) {
    73. return ROMs.at(index.row()).section(";", 6, 6);
    74. }
    75. if (index.column() == 7) { // Compañia
    76.  
    77. return ROMs.at(index.row()).section(";", 7, 7);
    78.  
    79. }
    80. if (index.column() == 8) {
    81.  
    82. return ROMs.at(index.row()).section(";", 8, 8);
    83.  
    84. }
    85. if (index.column() == 9) {
    86.  
    87. return ROMs.at(index.row()).section(";", 9, 9);
    88.  
    89. }
    90. if (index.column() == 11) {
    91. return ROMs.at(index.row()).section(";", 10, 10);
    92. }
    93.  
    94. }
    95.  
    96. return QVariant();
    97. }
    To copy to clipboard, switch view to plain text mode 

    any help, clue, or anything is appreciated, anything that can help me to put end my QTableHell
    thanks
    Always trying to learn >.<

  2. #2
    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: QTableView sort column with numbers very slow

    Did you try profiling your app? Instead of chasing ghosts, it will tell you which parts of your program take most time to execute.

    What does this section() do?
    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.


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

    Default Re: QTableView sort column with numbers very slow

    the list of games is a QStringList like name;language;path;etc... so i use section() to get each column data.

    About profiling i'm not sure what it means, i'll google for it (i'm newbie in programming in general)
    I'll try anything, this problem is killing me. Maybe Qt can't sort 15.000 rows in < 1 second?

    EDIT: i did it (at leas that seems), the problem was the section()
    Last edited by aguayro; 18th January 2013 at 03:15.
    Always trying to learn >.<

  4. #4
    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: QTableView sort column with numbers very slow

    How did you solve it?
    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.


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

    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 >.<

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

    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.