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. Qt program remains running after calling QGraphicsProxyWidget::setWidget()
Forum Updated to NodeBB v4.3 + New Features

Qt program remains running after calling QGraphicsProxyWidget::setWidget()

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 601 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.
  • N Offline
    N Offline
    Niagarer
    wrote on 21 Feb 2020, 15:01 last edited by
    #1

    Hi,
    let's just give an example: (PySide2 but I am quite sure I also saw the exact same thing happening in C++ applications)

    import sys
    
    from PySide2.QtWidgets import QMainWindow, QApplication, QGraphicsView, QGraphicsScene, QGraphicsProxyWidget, QWidget
    
    
    class MyView(QGraphicsView):
        def __init__(self):
            super(MyView, self).__init__()
    
            scene = QGraphicsScene(self)
            scene.setSceneRect(0, 0, self.width(), self.height())
            self.setScene(scene)
    
            self.myproxy = QGraphicsProxyWidget()
            self.myproxy.setWidget(QWidget())
            #self.scene().addItem(self.myproxy)
    
    
    class MainWindow(QMainWindow):
        def __init__(self):
            super(MainWindow, self).__init__()
            self.setCentralWidget(MyView())
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        mw = MainWindow()
        mw.show()
    
        sys.exit(app.exec_())
    

    This program still keeps running after closing the window, but it only does when calling self.myproxy.setWidget(QWidget()). Yes, I don't even have to add it to the scene, to produce this behavior.
    Can you see what is causing this?
    Thanks for answers!

    J 1 Reply Last reply 21 Feb 2020, 16:26
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 21 Feb 2020, 19:06 last edited by
      #5

      Do you use 5.14.0? If so please upgrade to 5.14.1: https://bugreports.qt.io/browse/QTBUG-81107

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

      J N 2 Replies Last reply 21 Feb 2020, 19:07
      4
      • N Niagarer
        21 Feb 2020, 15:01

        Hi,
        let's just give an example: (PySide2 but I am quite sure I also saw the exact same thing happening in C++ applications)

        import sys
        
        from PySide2.QtWidgets import QMainWindow, QApplication, QGraphicsView, QGraphicsScene, QGraphicsProxyWidget, QWidget
        
        
        class MyView(QGraphicsView):
            def __init__(self):
                super(MyView, self).__init__()
        
                scene = QGraphicsScene(self)
                scene.setSceneRect(0, 0, self.width(), self.height())
                self.setScene(scene)
        
                self.myproxy = QGraphicsProxyWidget()
                self.myproxy.setWidget(QWidget())
                #self.scene().addItem(self.myproxy)
        
        
        class MainWindow(QMainWindow):
            def __init__(self):
                super(MainWindow, self).__init__()
                self.setCentralWidget(MyView())
        
        
        if __name__ == '__main__':
            app = QApplication(sys.argv)
        
            mw = MainWindow()
            mw.show()
        
            sys.exit(app.exec_())
        

        This program still keeps running after closing the window, but it only does when calling self.myproxy.setWidget(QWidget()). Yes, I don't even have to add it to the scene, to produce this behavior.
        Can you see what is causing this?
        Thanks for answers!

        J Offline
        J Offline
        JonB
        wrote on 21 Feb 2020, 16:26 last edited by
        #2

        @Niagarer
        I don't know the answer but: a Qt app only exits after closing the last window it has open, as per https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop. So my guess is that it sees your self.myproxy.setWidget(QWidget()) as contravening:

        the applications quits when the last visible primary window (i.e. window with no parent) is closed.

        We certainly know that QGraphicsProxyWidget::setWidget requires a top-level (no parent) widget, like your QWidget().

        Do you need to worry yourself over the reason, or would you be happy to just close/destroy these widgets which keep your app from closing?

        N 1 Reply Last reply 21 Feb 2020, 16:39
        0
        • J JonB
          21 Feb 2020, 16:26

          @Niagarer
          I don't know the answer but: a Qt app only exits after closing the last window it has open, as per https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop. So my guess is that it sees your self.myproxy.setWidget(QWidget()) as contravening:

          the applications quits when the last visible primary window (i.e. window with no parent) is closed.

          We certainly know that QGraphicsProxyWidget::setWidget requires a top-level (no parent) widget, like your QWidget().

          Do you need to worry yourself over the reason, or would you be happy to just close/destroy these widgets which keep your app from closing?

          N Offline
          N Offline
          Niagarer
          wrote on 21 Feb 2020, 16:39 last edited by Niagarer
          #3

          @JonB
          Well, I agree, but closing the window actually closes the last visible element (the main window).
          Destroying the ProxyWidgets manually wouldn't be a nice way in bigger applications (from what I know, Qt's widgets actually shouldn't behave like that but I am probably missing something). A couple of months ago, I wrote a similar C++ app with the same problem which sometimes caused a windows memory reference error when trying to shut down the computer which is kinda wired... : /
          So, I would really like to find out the reason for that

          J 1 Reply Last reply 21 Feb 2020, 18:56
          0
          • N Niagarer
            21 Feb 2020, 16:39

            @JonB
            Well, I agree, but closing the window actually closes the last visible element (the main window).
            Destroying the ProxyWidgets manually wouldn't be a nice way in bigger applications (from what I know, Qt's widgets actually shouldn't behave like that but I am probably missing something). A couple of months ago, I wrote a similar C++ app with the same problem which sometimes caused a windows memory reference error when trying to shut down the computer which is kinda wired... : /
            So, I would really like to find out the reason for that

            J Offline
            J Offline
            JonB
            wrote on 21 Feb 2020, 18:56 last edited by JonB
            #4

            @Niagarer said in Qt program remains running after calling QGraphicsProxyWidget::setWidget():

            Well, I agree, but closing the window actually closes the last visible element (the main window).

            I do not disagree with you. But I did not write Qt, I'm just guessing that the reason your app does not exit is connected to this.

            Maybe you could close any top-level widgets when the user goes to close the main window. At least just to see if that proves this is the issue and resolves it. Certainly anything seems preferable to leaving your app running invisibly.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 21 Feb 2020, 19:06 last edited by
              #5

              Do you use 5.14.0? If so please upgrade to 5.14.1: https://bugreports.qt.io/browse/QTBUG-81107

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

              J N 2 Replies Last reply 21 Feb 2020, 19:07
              4
              • C Christian Ehrlicher
                21 Feb 2020, 19:06

                Do you use 5.14.0? If so please upgrade to 5.14.1: https://bugreports.qt.io/browse/QTBUG-81107

                J Offline
                J Offline
                JonB
                wrote on 21 Feb 2020, 19:07 last edited by
                #6

                @Christian-Ehrlicher Ah ha!

                1 Reply Last reply
                0
                • C Christian Ehrlicher
                  21 Feb 2020, 19:06

                  Do you use 5.14.0? If so please upgrade to 5.14.1: https://bugreports.qt.io/browse/QTBUG-81107

                  N Offline
                  N Offline
                  Niagarer
                  wrote on 21 Feb 2020, 19:12 last edited by
                  #7

                  @Christian-Ehrlicher
                  thank you!! That was exactly it!
                  It works now. Didn't assume it to be a bug, since I already experienced this a year ago, but thank you!

                  1 Reply Last reply
                  1

                  4/7

                  21 Feb 2020, 18:56

                  • Login

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