Qt program remains running after calling QGraphicsProxyWidget::setWidget()
-
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! -
Do you use 5.14.0? If so please upgrade to 5.14.1: https://bugreports.qt.io/browse/QTBUG-81107
-
@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 yourself.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 yourQWidget()
.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?
-
@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 -
@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.
-
Do you use 5.14.0? If so please upgrade to 5.14.1: https://bugreports.qt.io/browse/QTBUG-81107
-
@Christian-Ehrlicher Ah ha!
-
@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!