Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-42618

QQuickWidget crash when closing QMdiSubWindow

    XMLWordPrintable

Details

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              lagocs Laszlo Agocs
              anylitok Antti Yli-Tokola (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes