Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Find *ALL* QGraphicsItems?

Find *ALL* QGraphicsItems?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 715 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    For developing/debugging, I found QWidgetList QApplication::allWidgets() very useful, especially to track down "orphaned" widgets.

    Now moving to QGraphicsScene I don't see/suppose there is any equivalent to walk all QGraphicsItems created in the application, an equivalent QApplication::allGraphicsItems()? The whole point is to find any which do not have a parent QGrapchicsScene, so QGraphicsScene::items() is not going to help me....

    1 Reply Last reply
    1
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #8

      Ok, then 'no' :)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      JonBJ 1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        What kind of parentless items do you have in mind ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        JonBJ 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          What kind of parentless items do you have in mind ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #3

          @SGaist

          1. Any QGraphicsItem created via new QGraphicsItem::QGraphicsItem(nullptr) and then not later added via QGraphicsScene::addItem().

          2. Any QGraphicsItem created via new QGraphicsItem::QGraphicsItem(parentQGraphicsItem) which, when then you walk up the parentQGraphicsItem tree, ends up at an ancestor created via new QGraphicsItem::QGraphicsItem(nullptr).

          3. Any QGraphicsItem removed via QGraphicsScene::removeItem() where the caller has failed to then delete/deleteLater() the item and/or its descendants.

          4. Any QGraphicsItem which I think I have removed/deleted, but Python is still holding a reference to, for whatever reason.

          5. The ability in debugging code to be able to search all QGraphicsScenes the app might have with items where, for whatever reason, I do not have/it is not convenient to have a list of the top-level QGraphicsScenes to pass to it as parameters in order to do the descent walking, and so would like a "global" list to get going from.

          That's a start! Remember, this is for developing/debugging.

          I used this principle via QApplication.allWidgets() in last project debugging, and believe me it did show up "orphans" which I had to deal with!

          As you know, in other people's posts we quite often point out that have done some new QWidget() but failed to parent it or delete it, and are therefore leaking. If they tried walking QApplication.allWidgets() they would spot these, including the "nasty" where they have a whole bunch of widgets with parents but the top-level parent is orphaned (which my walk code detects), and are therefore leaking a lot....

          1 Reply Last reply
          1
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            This is a task for a memory leak check like e.g. valgrind. Since you're responsible for the objects you create, you have to take care to delete them (or use a proper parent-child relationship). I don't see how Qt can do something for you here since it's basic c++.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              This is a task for a memory leak check like e.g. valgrind. Since you're responsible for the objects you create, you have to take care to delete them (or use a proper parent-child relationship). I don't see how Qt can do something for you here since it's basic c++.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #5

              @Christian-Ehrlicher
              You know I respect your input, but sorry I don't think you're being reasonable. I'm not programming in C++. valgrind does not work at all well with Python. You cannot use it examine relationships, print out hierarchies etc. of what is there as you can from within your own code. "proper parent-child relationship" is not at all the whole story from Python as it is from C++.

              What you say applies just as much as QApplication.allWidgets(), yet that seems to (happen to) be provided, where (from my investigations so far) QApplication.allGraphicsItems() does not. I merely asked if anyone knew of something like that I could use. Qt could choose to do that. If the answer is no there is not, that's it. I'm not criticising Qt, I'm just asking....

              1 Reply Last reply
              1
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @JonB said in Find *ALL* QGraphicsItems?:

                Qt could choose to do that.

                Sorry but Qt is not responsible for your memory management. If you want something like a management for this you have to do it on your own.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                JonBJ 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @JonB said in Find *ALL* QGraphicsItems?:

                  Qt could choose to do that.

                  Sorry but Qt is not responsible for your memory management. If you want something like a management for this you have to do it on your own.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #7

                  @Christian-Ehrlicher
                  Forget everything about memory management. I asked whether anyone knows if Qt provides an application-level QApplication.allGraphicsItems()-type method, or equivalent, like it does for QApplication.allWidgets()? Very simple question.

                  If you or @SGaist feel fairly sure the answer is no, as I presume it is though nobody will just say so, shall I just close this issue?

                  1 Reply Last reply
                  1
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    Ok, then 'no' :)

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    JonBJ 1 Reply Last reply
                    3
                    • Christian EhrlicherC Christian Ehrlicher

                      Ok, then 'no' :)

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #9

                      @Christian-Ehrlicher

                      Ok, then 'no' :)

                      Soooo much better, clearer & quicker! :) I appreciate your time & input. As you can see, I have marked that as the Solution Answer. Thank you!

                      1 Reply Last reply
                      2

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved