Deleting QQuickView on exit cause Qt application to freeze

1.7k views Asked by At

I founded a deadlock in Qt 5.3. How to fix in correctly? Without ugly fix (not to delete qquickview *)

I have a singleton with a pointer to QQuickView. When I need to close my application I do a call of QGuiApplication::quit() and try to release QQuickView * in destructor of singlenot. Result - application freezes.

Sample:

test.qml

import QtQuick 2.1

Rectangle
{
    id: root;
    color: "black";

    signal quit();
    Component.onDestruction: quit();
}

main.cpp

#include <QGuiApplication>
#include <QQuickView>
#include <QQuickItem>
#include <QPointer>


struct Singleton
{
    QPointer< QQuickView > w;
    static Singleton inst;

    int run( int argc, char *argv[] )
    {
        QGuiApplication a( argc, argv );
        w = new QQuickView();

        QObject::connect( w, &QQuickView::statusChanged, [=]()
        {
            QObject::connect( w->rootObject(), SIGNAL( quit() ), qApp, SLOT( quit() ) );
        } );

        w->setSource( QUrl( "qrc:/test.qml" ) );
        w->setResizeMode( QQuickView::SizeRootObjectToView );
        w->show();

        a.exec();

        return 0;
    }

    ~Singleton()
    {
        delete w;   // Comment this to fix bug
    }

};

Singleton Singleton::inst;


int main(int argc, char *argv[] )
{
    Singleton::inst.run( argc, argv );
    return 0;
}

P.S. C++0x is used for simplifying code. Same result on C++03 compilers.

1

There are 1 answers

0
Dmitry Sazonov On BEST ANSWER

It was a bug in Qt. Fixed since 5.4 version.