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. Pyside6 how to disconnect connection?
QtWS25 Last Chance

Pyside6 how to disconnect connection?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicssceneqgraphicsitemqobjesignal
34 Posts 5 Posters 12.5k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 30 Dec 2020, 22:30 last edited by
    #1

    Hey

    I've got a wee of a problem with my QGraphicsScene and QGraphicsItem that I made... I have connection like this >
    self.scene().pinReleaseEvent.connect(self.pinReleaseEvent)
    Say when I want to delete the object... I do >
    self.scene().removeItem(self)
    Now I delete item with >
    shiboken6.delete(self)
    As QGraphicScene will no longer do it for me...

    The problem is that my signal is still "connected" somehow, how can I disconnect it properly?
    Using PySide6

    TIA

    E 1 Reply Last reply 30 Dec 2020, 23:08
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 30 Dec 2020, 22:38 last edited by mrjj
      #2

      Hi
      You could call disconnect on it before deleting it ?
      https://doc.qt.io/qtforpython/PySide6/QtCore/QObject.html#PySide6.QtCore.PySide6.QtCore.QObject.disconnect

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jeremy_k
        wrote on 30 Dec 2020, 22:47 last edited by
        #3

        With C++ and PyQt, connections involving deleted senders or receivers (except lambda functions in some cases) are automatically disconnected. Does PySide not do that?

        Asking a question about code? http://eel.is/iso-c++/testcase/

        M 1 Reply Last reply 30 Dec 2020, 22:55
        1
        • J jeremy_k
          30 Dec 2020, 22:47

          With C++ and PyQt, connections involving deleted senders or receivers (except lambda functions in some cases) are automatically disconnected. Does PySide not do that?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 30 Dec 2020, 22:55 last edited by
          #4

          @jeremy_k
          They should as far as i know so i do wonder how it can be still connected.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dariusz
            wrote on 30 Dec 2020, 23:07 last edited by
            #5

            Hey

            Heh about 5 mins after posting it I figured it out sigh! Yeah u were right. It was just self.scene().pinReleaseEvent.disconnect(self.pinReleaseEvent)
            Not quite sure why they don't auto disconnect. But I'm having a hell of a time to properly delete objects from QGraphicsScene...

            When I use shiboken6, does it also remove child items? Like child graphics/proxy widgets attached to that widget too or just the main widget? I keep on getting
            RuntimeError: Internal C++ object (layerWidgetHelper) already deleted.

            1 Reply Last reply
            0
            • D Dariusz
              30 Dec 2020, 22:30

              Hey

              I've got a wee of a problem with my QGraphicsScene and QGraphicsItem that I made... I have connection like this >
              self.scene().pinReleaseEvent.connect(self.pinReleaseEvent)
              Say when I want to delete the object... I do >
              self.scene().removeItem(self)
              Now I delete item with >
              shiboken6.delete(self)
              As QGraphicScene will no longer do it for me...

              The problem is that my signal is still "connected" somehow, how can I disconnect it properly?
              Using PySide6

              TIA

              E Offline
              E Offline
              eyllanesc
              wrote on 30 Dec 2020, 23:08 last edited by
              #6

              @Dariusz Why do you say The problem is that my signal is still "connected" somehow? could you provide a minimal and reproducible example

              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

              D 1 Reply Last reply 30 Dec 2020, 23:11
              0
              • E eyllanesc
                30 Dec 2020, 23:08

                @Dariusz Why do you say The problem is that my signal is still "connected" somehow? could you provide a minimal and reproducible example

                D Offline
                D Offline
                Dariusz
                wrote on 30 Dec 2020, 23:11 last edited by
                #7

                @eyllanesc said in Pyside6 how to disconnect connection?:

                @Dariusz Why do you say The problem is that my signal is still "connected" somehow? could you provide a minimal and reproducible example

                I wish I could but that is a problem in quite "large" app. I'm trying to clean it up with memory now and object deletion. As far as I could tell removing item from view & deleting it. If I interacted with view he would still call the item function & crash.

                E 1 Reply Last reply 30 Dec 2020, 23:14
                0
                • D Dariusz
                  30 Dec 2020, 23:11

                  @eyllanesc said in Pyside6 how to disconnect connection?:

                  @Dariusz Why do you say The problem is that my signal is still "connected" somehow? could you provide a minimal and reproducible example

                  I wish I could but that is a problem in quite "large" app. I'm trying to clean it up with memory now and object deletion. As far as I could tell removing item from view & deleting it. If I interacted with view he would still call the item function & crash.

                  E Offline
                  E Offline
                  eyllanesc
                  wrote on 30 Dec 2020, 23:14 last edited by
                  #8

                  @Dariusz I think that the problem is another, or your implementation does not generate the behavior you expect, so it is necessary that you provide an MRE in order to analyze the cause or solution of the problem. I have not asked you for the code of your project, if your project is small then it can be an MRE, but I have asked you to create another script focused on the functionality that generates problems.

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jeremy_k
                    wrote on 30 Dec 2020, 23:14 last edited by jeremy_k
                    #9

                    This might fall into that lambda exception I hinted at. If self is a QGraphicsItem, that isn't derived from QObject, and as such doesn't get the automatic disconnection behavior.

                    https://doc.qt.io/qt-6/qobject.html#connect-4 is the C++ equivalent.

                    Asking a question about code? http://eel.is/iso-c++/testcase/

                    D 1 Reply Last reply 30 Dec 2020, 23:17
                    1
                    • E Offline
                      E Offline
                      eyllanesc
                      wrote on 30 Dec 2020, 23:16 last edited by
                      #10

                      I see that many users are trying to help but because of the little information they are throwing things to see if one hits the wall but if you want quality help then generate the minimum space: the MRE

                      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                      1 Reply Last reply
                      0
                      • J jeremy_k
                        30 Dec 2020, 23:14

                        This might fall into that lambda exception I hinted at. If self is a QGraphicsItem, that isn't derived from QObject, and as such doesn't get the automatic disconnection behavior.

                        https://doc.qt.io/qt-6/qobject.html#connect-4 is the C++ equivalent.

                        D Offline
                        D Offline
                        Dariusz
                        wrote on 30 Dec 2020, 23:17 last edited by
                        #11

                        @jeremy_k said in Pyside6 how to disconnect connection?:

                        This might fall into that lambda exception I hinted at. If self is a QGraphicsItem, that isn't derived from QObject, and as such doesn't get the automatic disconnection behavior.

                        https://doc.qt.io/qt-6/qobject.html#connect-4 is the C++ equivalent.

                        I think that you are right. QGraphicsItem is not QObject, thus it does not have auto clean up functionality. I believe that's why I have to manually clean up connections.

                        E 1 Reply Last reply 30 Dec 2020, 23:19
                        0
                        • E Offline
                          E Offline
                          eyllanesc
                          wrote on 30 Dec 2020, 23:18 last edited by
                          #12

                          Note: Using shiboken2.delete does not remove the python object (the wrapper) but only the handled C++ object.

                          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                          D 1 Reply Last reply 30 Dec 2020, 23:19
                          0
                          • E eyllanesc
                            30 Dec 2020, 23:18

                            Note: Using shiboken2.delete does not remove the python object (the wrapper) but only the handled C++ object.

                            D Offline
                            D Offline
                            Dariusz
                            wrote on 30 Dec 2020, 23:19 last edited by
                            #13

                            @eyllanesc said in Pyside6 how to disconnect connection?:

                            Note: Using shiboken2.delete does not remove the python object (the wrapper) but only the handled C++ object.

                            This is frustrating... I miss C++ aff!
                            So shibokeh delete the C++ obejct, how do I delete python Object? del self ?

                            E J 2 Replies Last reply 30 Dec 2020, 23:21
                            0
                            • D Dariusz
                              30 Dec 2020, 23:17

                              @jeremy_k said in Pyside6 how to disconnect connection?:

                              This might fall into that lambda exception I hinted at. If self is a QGraphicsItem, that isn't derived from QObject, and as such doesn't get the automatic disconnection behavior.

                              https://doc.qt.io/qt-6/qobject.html#connect-4 is the C++ equivalent.

                              I think that you are right. QGraphicsItem is not QObject, thus it does not have auto clean up functionality. I believe that's why I have to manually clean up connections.

                              E Offline
                              E Offline
                              eyllanesc
                              wrote on 30 Dec 2020, 23:19 last edited by
                              #14

                              @Dariusz The connection you show is not made by the QGraphicsItem but by the scene, so the one that removes the connection in the last instance is the scene.

                              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                              J 1 Reply Last reply 30 Dec 2020, 23:26
                              0
                              • D Dariusz
                                30 Dec 2020, 23:19

                                @eyllanesc said in Pyside6 how to disconnect connection?:

                                Note: Using shiboken2.delete does not remove the python object (the wrapper) but only the handled C++ object.

                                This is frustrating... I miss C++ aff!
                                So shibokeh delete the C++ obejct, how do I delete python Object? del self ?

                                E Offline
                                E Offline
                                eyllanesc
                                wrote on 30 Dec 2020, 23:21 last edited by eyllanesc
                                #15

                                @Dariusz said in Pyside6 how to disconnect connection?:
                                In python you can't delete an object, del only deletes the variable name but not the object(the memory space). I don't understand why deleting an item must imply deleting the connection that is in the scope of the scene.

                                If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                                1 Reply Last reply
                                0
                                • D Dariusz
                                  30 Dec 2020, 23:19

                                  @eyllanesc said in Pyside6 how to disconnect connection?:

                                  Note: Using shiboken2.delete does not remove the python object (the wrapper) but only the handled C++ object.

                                  This is frustrating... I miss C++ aff!
                                  So shibokeh delete the C++ obejct, how do I delete python Object? del self ?

                                  J Offline
                                  J Offline
                                  jeremy_k
                                  wrote on 30 Dec 2020, 23:21 last edited by
                                  #16

                                  @Dariusz said in Pyside6 how to disconnect connection?:

                                  @eyllanesc said in Pyside6 how to disconnect connection?:

                                  Note: Using shiboken2.delete does not remove the python object (the wrapper) but only the handled C++ object.

                                  This is frustrating... I miss C++ aff!
                                  So shibokeh delete the C++ obejct, how do I delete python Object? del self ?

                                  That, or remove all references to the item. If the object isn't referenced via a variable that is in scope somewhere else, the python garbage collector should eventually clean up.

                                  Asking a question about code? http://eel.is/iso-c++/testcase/

                                  E 1 Reply Last reply 30 Dec 2020, 23:22
                                  0
                                  • J jeremy_k
                                    30 Dec 2020, 23:21

                                    @Dariusz said in Pyside6 how to disconnect connection?:

                                    @eyllanesc said in Pyside6 how to disconnect connection?:

                                    Note: Using shiboken2.delete does not remove the python object (the wrapper) but only the handled C++ object.

                                    This is frustrating... I miss C++ aff!
                                    So shibokeh delete the C++ obejct, how do I delete python Object? del self ?

                                    That, or remove all references to the item. If the object isn't referenced via a variable that is in scope somewhere else, the python garbage collector should eventually clean up.

                                    E Offline
                                    E Offline
                                    eyllanesc
                                    wrote on 30 Dec 2020, 23:22 last edited by
                                    #17

                                    @jeremy_k Exactly, that's why I think the OP has an XY problem

                                    If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                                    D 1 Reply Last reply 30 Dec 2020, 23:23
                                    0
                                    • E eyllanesc
                                      30 Dec 2020, 23:22

                                      @jeremy_k Exactly, that's why I think the OP has an XY problem

                                      D Offline
                                      D Offline
                                      Dariusz
                                      wrote on 30 Dec 2020, 23:23 last edited by
                                      #18

                                      @eyllanesc said in Pyside6 how to disconnect connection?:

                                      @jeremy_k Exactly, that's why I think the OP has an XY problem

                                      Well the initial signal problem is now solved. Since I delete items and scene remain active, scene does not clean up connections. So I have to manually clean them up.

                                      My second problem is how to properly delete a qgraphicsitem with its children in python. Perhaps I should make another topic for that as this one has solved my main issue.

                                      E 1 Reply Last reply 30 Dec 2020, 23:26
                                      0
                                      • D Dariusz
                                        30 Dec 2020, 23:23

                                        @eyllanesc said in Pyside6 how to disconnect connection?:

                                        @jeremy_k Exactly, that's why I think the OP has an XY problem

                                        Well the initial signal problem is now solved. Since I delete items and scene remain active, scene does not clean up connections. So I have to manually clean them up.

                                        My second problem is how to properly delete a qgraphicsitem with its children in python. Perhaps I should make another topic for that as this one has solved my main issue.

                                        E Offline
                                        E Offline
                                        eyllanesc
                                        wrote on 30 Dec 2020, 23:26 last edited by
                                        #19

                                        @Dariusz I don't understand how you have solved your current problem, and so far I don't understand what the connection (or disconnection) of the pinReleaseEvent signal of the scene has to do with the elimination of an item since they are 2 different objects. If anyone understands please explain it to me

                                        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                                        1 Reply Last reply
                                        1
                                        • E eyllanesc
                                          30 Dec 2020, 23:19

                                          @Dariusz The connection you show is not made by the QGraphicsItem but by the scene, so the one that removes the connection in the last instance is the scene.

                                          J Offline
                                          J Offline
                                          jeremy_k
                                          wrote on 30 Dec 2020, 23:26 last edited by
                                          #20

                                          @eyllanesc said in Pyside6 how to disconnect connection?:

                                          @Dariusz The connection you show is not made by the QGraphicsItem but by the scene, so the one that removes the connection in the last instance is the scene.

                                          The issue is that the QGraphicsItem is on the receiving end of the connection, and is effectively captured. The caller doesn't know that the captured item is no longer valid, leading to an invalid condition at call time. In C++, it would be undefined behavior. I don't know what the python terminology is.

                                          Generic C++ example:

                                          int *i = new int;
                                          *i = 0;
                                          auto f = [i]() { *i++; };
                                          delete i;
                                          f();
                                          

                                          Asking a question about code? http://eel.is/iso-c++/testcase/

                                          E 1 Reply Last reply 30 Dec 2020, 23:29
                                          0

                                          1/34

                                          30 Dec 2020, 22:30

                                          • Login

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