Results 1 to 2 of 2

Thread: Adding millions of GraphicsItems is slow

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Adding millions of GraphicsItems is slow

    Hi,
    I have code like this:
    Qt Code:
    1. scene->set_brush(this->get_lp()->get_brush());
    2. scene->set_pen(this->get_lp()->get_pen());
    3. QListIterator<db_rect *> iter_rect(this->rect_list);
    4. while(iter_rect.hasNext()) {
    5. rect = iter_rect.next();
    6. scene->addItem(rect);
    7. }
    8. QListIterator<db_box *> iter_box(this->box_list);
    9. while(iter_box.hasNext()) {
    10. box = (db_box *) iter_box.next();
    11. scene->addItem(box);
    12. }
    13. QListIterator<db_path *> iter_path(this->path_list);
    14. while(iter_path.hasNext()) {
    15. path = iter_path.next();
    16. scene->addItem(path);
    17. }
    18. QListIterator<db_polygon *> iter_polygon(this->polygon_list);
    19. while(iter_polygon.hasNext()) {
    20. polygon = iter_polygon.next();
    21. scene->addItem(polygon);
    22. }
    23. QListIterator<db_text *> iter_text(this->text_list);
    24. while(iter_text.hasNext()) {
    25. text = iter_text.next();
    26. scene->addItem(text);
    27. }
    To copy to clipboard, switch view to plain text mode 


    Works great when I have thousands of objects. However, when I add millions, it is awfully slow. I am sure I am missing something. I was trying to figure out how to paint on a pixmap when using addItem but to no avail.
    Please help.

    Thanks -- RK
    Last edited by wysota; 28th April 2009 at 07:15. Reason: missing [code] tags

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

    Default Re: Adding millions of GraphicsItems is slow

    If you have millions of objects then unfortunately you have to go through those loops millions of times and there is not much you can do about it. You might just reduce slowdowns related to the architecture yourself - create a scene, add all the items and only then set the scene on a view. You might also try disabling indexing during addition of items although I'm not convinced this will help.
    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.


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.