Results 1 to 7 of 7

Thread: QGraphicsScene sorting takes a lot of time

  1. #1
    Join Date
    May 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QGraphicsScene sorting takes a lot of time

    I have a QGraphicsScene, it contains about 200000 items(this items a added in the beginning of app). Everything works excellent until i have tried to add one more item on the scene, then app hang over ~5 minute for completing this operation.

    Callstack operations, which repeat while app hangs

    qt_closestLeaf qgraphicsitem_p.h
    qt_notclosestLeaf qgraphicsitem_p.h
    QAlgorithmsPrivate::qSortHelper<QList<QGraphicsIte m*>::iterator, QGraphicsItem*, bool
    (*)(QGraphicsItem const*, QGraphicsItem const*)> qalgorithms.h
    qSort<QList<QGraphicsItem*>::iterator, bool (*)(QGraphicsItem const*, QGraphicsItem const*)>
    qalgorithms.h
    QGraphicsScenePrivate::ensureSortedTopLevelItems qgraphicsscene_p.h
    QGraphicsSceneIndex::estimateTopLevelItems qgraphicssceneindex.cpp
    QGraphicsScenePrivate::drawItems qgraphicsscene.cpp
    QGraphicsView::paintEvent qgraphicsview.cpp
    QWidget::event qwidget.cpp

    I can't understand what is the problem.
    What can I do to solve this problem?

    Qt 4.6.2 OS Linux
    Sorry for my English.

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

    Default Re: QGraphicsScene sorting takes a lot of time

    What is the type of items you are adding? If they are your own ones, how is boundingRect() defined for them? Also haven't you by any chance disabled indexing in the scene?
    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 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene sorting takes a lot of time

    Quote Originally Posted by wysota View Post
    What is the type of items you are adding? If they are your own ones, how is boundingRect() defined for them? Also haven't you by any chance disabled indexing in the scene?
    I'm adding QGraphicsEllipseItem, boundingRect() defined in QGraphicsElliplseItem. If index is enable app hangs when items() is called in QGraphicsScene, for example, when I hide and show window , if index is disable app hangs after I have called addItem().
    QGraphicsScene always sorts items when I add item (sorting time ~5 minute), but I think this is my problem. What do you think about it?

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

    Default Re: QGraphicsScene sorting takes a lot of time

    If you have so many items I would strongly advise against disabling the index if you wish to have any interaction with the scene. Try avoiding calling items(), it returns all of your items, it is hard to come up with a situation when you needed to access them all. And the list needs to be sorted first. Sorting takes O(n*lgn) which for 200000 items is a huge number of comparisons to perform.
    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
    May 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene sorting takes a lot of time

    wysota Thanks for your answers, but problem is more complex.
    Function items() is called from many other QGraphicsView's functions, for example when window is hid and shown again QGraphicsView:aintEvent() is called and it uses items(QRectF) and other(each function try to sort items). If I don't add item to Scene, all works good. Why addition of one more item makes so long sort, but first 200000 additions work well and without any problems.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QGraphicsScene sorting takes a lot of time

    Quote Originally Posted by f-r-o-s-t View Post
    If I don't add item to Scene, all works good.
    Because if you add an item to the scene without the index, you break all the caches and everything has to be recalculated. Keep indexing enabled.
    Why addition of one more item makes so long sort, but first 200000 additions work well and without any problems.
    Maybe your machine starts swapping?
    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.


  7. #7
    Join Date
    May 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene sorting takes a lot of time

    wysota, thanks for your answers.
    Index was enabled always, i disable it for experiment.
    Problem was in zValue which i made equal for many items, as result i had an unbalanced tree and long sorting time.
    After zValue was changed my app works very fast. I'm happy!

Similar Threads

  1. QTextEdit loading takes long time
    By sreedhar in forum Qt Programming
    Replies: 12
    Last Post: 21st March 2011, 10:29
  2. Hello World app takes ages to start on WM6
    By fabiobond in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 30th July 2010, 08:03
  3. QImage::scaled takes long time
    By nrabara in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 12:19
  4. QGraphicsItem.setPos takes a lot of time
    By ricofe25 in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2009, 19:28
  5. Can QByteArray takes place of BYTE?
    By hiuao in forum Qt Programming
    Replies: 2
    Last Post: 5th April 2007, 11:49

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.