Results 1 to 2 of 2

Thread: QTreeView and SQL - Performance Advice

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    30
    Thanks
    2

    Default QTreeView and SQL - Performance Advice

    Hi,

    I have an app where I want to show SQL query results in a hierarchical structure. I have something work that is based on this example:
    http://doc.qt.nokia.com/latest/itemv...treemodel.html

    The main part of my code where the tree nodes are created currently looks like this:
    Qt Code:
    1. void TreeModel::setupModelData(TreeItem *parent)
    2. {
    3. QList<TreeItem*> parents;
    4. QList<int> indentations;
    5. parents << parent;
    6. QList<QVariant> columnData;
    7.  
    8. QVector<QString> vecFileNames = getFileNames();
    9. QVector<QString> vecTableNames = getTableNames();
    10.  
    11. for(int i = 0; i < vecFileNames.size(); i++)
    12. {
    13. columnData.clear();
    14. columnData << vecFileNames[i];
    15. parents.last()->appendChild(new TreeItem(columnData, parents.last()));
    16.  
    17. int childCount = parents.last()->childCount() - 1;
    18. parents << parents.last()->child(childCount); //add the current parent's last child as a parent
    19.  
    20. for(int j = 0; j < vecTableNames.size(); j++)
    21. {
    22. columnData.clear();
    23. columnData << vecTableNames[j];
    24. parents.last()->appendChild(new TreeItem(columnData, parents.last()));
    25.  
    26. QVector<QString> vecTableValues = getTableValues(&vecTableNames[j]);
    27. int childCount = parents.last()->childCount() - 1;
    28. parents << parents.last()->child(childCount); //add the current parent's last child as a parent
    29.  
    30. for(int k = 0; k < vecTableValues.size(); k++)
    31. {
    32. columnData.clear();
    33. columnData << vecTableValues[j];
    34. parents.last()->appendChild(new TreeItem(columnData, parents.last()));
    35. }
    36.  
    37. }
    38. parents.pop_back();
    39. }
    40.  
    41. }
    42.  
    43. QVector<QString> TreeModel::getFileNames()
    44. {
    45. db.open();
    46.  
    47. QVector<QString> vecFileNames;
    48. QSqlQuery query(db);
    49. QString strQuery = "SELECT PK_fileName FROM fileproperties";
    50. query.prepare(strQuery);
    51.  
    52. if(query.exec() == true)
    53. {
    54. while(query.next())
    55. {
    56. vecFileNames.push_back(query.value(0).toString());
    57. }
    58. }
    59.  
    60. db.close();
    61. return vecFileNames;
    62. }
    To copy to clipboard, switch view to plain text mode 

    However, it is incredibly slow retrieving 2000 queries worth of data.
    Can anyone suggest another approach to the one I'm using now?

  2. #2
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: QTreeView and SQL - Performance Advice

    you have three nested for loops so I would say that parsing the results takes time...
    maybe consider is it possible to put your code in the larger sql query
    database engine will do the job quicker than the code itself and than you could just pick up values for specific cells of the QSqlQuery and do only one for loop
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

Similar Threads

  1. Replies: 2
    Last Post: 31st July 2013, 17:06
  2. Sql Query with QTreeView - Advice
    By johnnyturbo3 in forum Newbie
    Replies: 9
    Last Post: 13th September 2010, 10:10
  3. QTreeView performance slowdown...
    By jpujolf in forum Qt Programming
    Replies: 10
    Last Post: 6th December 2008, 09:15
  4. QDirModel/QTreeView performance under win32
    By roxton in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2008, 18:26
  5. Practical QTreeView: Advice needed
    By Jojo in forum Qt Programming
    Replies: 13
    Last Post: 20th February 2006, 20:28

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.