Question

My application is designed in that way that different plugins can set the central widget of the main windows to show the desired content.

This works so far.

But if I set a QQuickView-WindowContainer as central widget, the app does not quit when I close the main window.

If I set a "normal" widget like QPushButton as central widget the appliation quits just fine. Why is that?

This is the code of a minimal example which shows this behaviour (MainWindow is a class created from the QtCreator wizard):

class AppCore : public QObject
{
    Q_OBJECT

    public:
        explicit AppCore(QObject *parent = 0);

    signals:

    public slots:
        void showMainWindow();

    private:
        MainWindow *m_mainWindow;
};

AppCore::AppCore(QObject *parent) :
    QObject(parent)
{
}

void AppCore::showMainWindow()
{
    QQuickView *view;
    QWidget *container;

    view = new QQuickView();
    container = QWidget::createWindowContainer(view);
    view->setSource(QUrl("qrc:/main.qml"));

    m_mainWindow = new MainWindow();

    //m_mainWindow->setCentralWidget(new QPushButton("Button"));
    m_mainWindow->setCentralWidget(container);

    m_mainWindow->show();
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    AppCore appCore;

    appCore.showMainWindow();;

    return a.exec();
}
Was it helpful?

Solution

This looks like a bug. I see a dead lock in debugger: v8::internal::RuntimeProfiler::WaitForSomeIsolateToEnterJS and QQmlDataLoader::shutdownThread wait for each other. I can't find a good workaround for this issue.

I found a dirty hack that solved the issue. If container is deleted a bit earlier, all works ok:

void MainWindow::closeEvent(QCloseEvent *e) {
  QMainWindow::closeEvent(e);
  if (e->isAccepted() && centralWidget()) {
    delete centralWidget();
  }
}

You probably should send a bug report. Note that m_mainWindow is not needed to reproduce the issue. Using container->show(); gives the same result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top