Results 1 to 4 of 4

Thread: QTreeWidget performance after QtConcurrent

  1. #1
    Join Date
    May 2011
    Posts
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QTreeWidget performance after QtConcurrent

    Hi,

    I am using QtConcurrent for a function to process number of objects in batch.
    For e.g. I have 1000 graphics objects, I call process() for 500 items and another call for remaining 500 items using two calls of QtConcurrent::run(...).
    I get good performance improvement here. But after process() function I use these processed items to populate items in QTreewidget.
    The time required to populate the QTreeWidget tremendously increases as compared to the time required for populating before we used QtConcurrent.


    I have a XML file which contains details of each of these items which includes id, position, height, width. My application reads this file and pass this detail to process() to creates the Item class objects.

    Qt Code:
    1. class Item :: QGraphicsObject
    2. {
    3. QString m_sId;
    4. int m_iHeight, m_iWidth;
    5. QPoint m_position;
    6. };
    7.  
    8. // process()
    9. process(int iStart, int iEnd, <list of XMLNode>)
    10. {
    11. for(iStart to iEnd)
    12. {
    13. // Read XMLNode and create Item object using the read details
    14. }
    15. }
    16.  
    17. // read()
    18.  
    19. read()
    20. {
    21. // Read the XML File
    22. QList<XMLNode> lstNodes = readXML();
    23.  
    24. // call process() for list of XMLNode
    25. QList<Item*> lstItems = process(1, lstNodes.size(), lstNodes);
    26.  
    27. // Add these items to scene using m_scene->addItem((QGraphicsItem*) item);
    28.  
    29. // Iterate through the list of items and add each of the item to QTreeWidget
    30. for(i = 0 to size )
    31. {
    32. Item* item = lstItems1.at(i);
    33. QTreeWidgetItem *treeItem = new QTreeWidgetItem(Items);
    34. treeItem->setText(0, tr(item->m_sId));
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

    Below is the modified code using QtConcurrent::run()

    Qt Code:
    1. // process()
    2. QList<Item*> process(int iStart, int iEnd, <list of XMLNode>)
    3. {
    4. QList<Item*> lstItems;
    5. for(iStart to iEnd)
    6. {
    7. // Read XMLNode and create Item object using the read details
    8. // Move the created graphics object on main thread as it needs to be added to scene later
    9. item.moveToThread(QApplication::instance()->thread());
    10. }
    11. return lstItems;
    12. }
    13.  
    14. read()
    15. {
    16. // Read the XML File
    17. QList<XMLNode> lstNodes = readXML();
    18.  
    19. // call process() for list of XMLNode
    20. int iSize = lstNodes.size();
    21.  
    22. QFutureSynchronizer<QList<Item*>> synchronizer;
    23.  
    24. QFuture<QList<Item*>> future1 = QtConcurrent::run(this, &Reader::process, 1, iSize/2, lstNodes);
    25. QFuture<QList<Item*>> future2 = QtConcurrent::run(this, &Reader::process, iSize/2, iSize, lstNodes);
    26.  
    27. synchronizer.addFuture(future1);
    28. synchronizer.addFuture(future2);
    29.  
    30. synchronizer.waitForFinished();
    31.  
    32. QList<Item*> lstItems1 = future1.result();
    33. QList<Item*> lstItems2 = future2.result();
    34.  
    35. lstItems1.append(lstItems2);
    36.  
    37. // Add these items to scene using m_scene->addItem((QGraphicsItem*) item);
    38.  
    39. // Iterate through the list of items and add each of the item to QTreeWidget
    40. for(int i = 0; i<= size; i++ )
    41. {
    42. Item* item = lstItems1.at(i);
    43. QTreeWidgetItem *treeItem = new QTreeWidgetItem(treeWidget);
    44. treeItem->setText(0, tr(item->m_sId));
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

    My problem is, previously populating the TreeWidget was taking less time (1.9 sec) for 1000 items but now when I used QtConcurrent for process(), it has been increased (21.5 sec) whereas calling process() using QtConcurrent takes less time.

    Can you please guide me resolving this issue?

  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: QTreeWidget performance after QtConcurrent

    Don't items one by one but rather do that in batches. For this you'll probably have to implement your own model and use QTreeView instead of QTreeWidget.
    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
    May 2011
    Posts
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget performance after QtConcurrent

    Thanks Wysota.

    Yes, I am planning to use QTreeView. But my concern here is the time has been substantially increased after i used QtConcurrent. Is that I have done something wrong here?

  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: QTreeWidget performance after QtConcurrent

    I don't think this is caused by QtConcurrent. For instance line #35 of your code snippet does not make much sense and also line #40 is simply invalid (you should get a segfault once i == size. My wild guess would be that your tree widget's header is set to adjust its width to its contents which is very slow if you keep adding items one by one.
    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.


Similar Threads

  1. QtConcurrent::mappedReduced
    By wookoon in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2010, 09:53
  2. qtconcurrent
    By knishaq in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2009, 09:41
  3. QtConcurrent Performance
    By tomf in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2008, 16:41
  4. QtConcurrent
    By Brandybuck in forum An Introduction to QThreads
    Replies: 2
    Last Post: 9th May 2008, 15:10
  5. Replies: 2
    Last Post: 17th March 2008, 13:53

Tags for this Thread

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.