Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.3.2, 5.4.0 Beta
-
Windows, Linux
Description
Use case is a bit different than in QTBUG-40435 so that's why new bug is created.
In this example there is another object (Panel), which is the logical owner of the Widget inside QMdiSubWindow, but when the user closes the subwindow, we need to also destroy this "logical owner". But as there are other ways in our application to also destroy the "Panel" instance, this needs to delete the widget in its destructor.
Steps to reproduce:
1. Start application and close the subwindow.
Same code works fine if QWidget is used instead of QQuickWidget.
#include <QApplication> #include <QMainWindow> #include <QMdiArea> #include <QMdiSubWindow> #include <QQuickWidget> #include <QDebug> #include <QPointer> class Panel; class PanelQT : public QWidget { public: PanelQT(Panel *p) : panel(p) { } ~PanelQT() { qDebug() << "dtor PanelQT"; } void closeEvent(QCloseEvent *ev); private: Panel *panel; }; class Panel : public QObject { public: Panel() { widget = new PanelQT(this); } ~Panel() { qDebug() << "dtor Panel"; delete widget; } QWidget *getWidget() const { return widget; } private: QPointer<PanelQT> widget; }; void PanelQT::closeEvent(QCloseEvent *ev) { ev->accept(); panel->deleteLater(); } int main(int argc, char **argv) { QApplication app(argc, argv); QMainWindow mw; QMdiArea *mdiArea = new QMdiArea; mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation); mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); mw.setCentralWidget(mdiArea); Panel *panel = new Panel; panel->getWidget()->resize(500, 500); QQuickWidget *quickWidget = new QQuickWidget(panel->getWidget()); // crashes //QWidget *quickWidget = new QWidget(panel->getWidget()); // works quickWidget->setGeometry(10, 10, 400, 400); QMdiSubWindow *subwindow = mdiArea->addSubWindow(panel->getWidget()); subwindow->resize(500, 500); subwindow->show(); mw.show(); return app.exec(); }
Attachments
Issue Links
- relates to
-
QTBUG-40435 QQuickWidget deleteLater crashes when removed from QMdiArea
-
- Closed
-