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()
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 547 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.
  • NiagarerN Offline
    NiagarerN Offline
    Niagarer
    wrote on 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!

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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

      JonBJ NiagarerN 2 Replies Last reply
      4
      • NiagarerN Niagarer

        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!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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?

        NiagarerN 1 Reply Last reply
        0
        • JonBJ JonB

          @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?

          NiagarerN Offline
          NiagarerN Offline
          Niagarer
          wrote on 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

          JonBJ 1 Reply Last reply
          0
          • NiagarerN Niagarer

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 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

              JonBJ NiagarerN 2 Replies Last reply
              4
              • Christian EhrlicherC Christian Ehrlicher

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

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

                @Christian-Ehrlicher Ah ha!

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

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

                  NiagarerN Offline
                  NiagarerN Offline
                  Niagarer
                  wrote on 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

                  • Login

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