[solved] Crash when creating QQuickView from QTimer event

  • I try to create a QQuickView in a function that is triggered by a timer, but it triggers an exception. (The inferior stopped because it triggered an exception. ...read access violation...) If I create a QQuickView manually before the timer triggers the function that creates a QQuickView, the program will not crash.
    Anybody know why this happens? What am I doing wrong?

    A bit of an bad explanation, but i hope the code explais it better.

    #include "app.h"
    #include <QTimer>

    App::App( int argc, char* argv[] )
    : QGuiApplication( argc, argv )
    , view( NULL )
    // If the line below is included the program works
    //QQuickView* tempView = new QQuickView();

    QTimer::singleShot( 5000, this, SLOT( createView() ) );


    void App::createView()
    view = new QQuickView();

    #ifndef APP_H
    #define APP_H

    #include <QGuiApplication>
    #include <QQuickView>

    class App : public QGuiApplication
    App( int, char** );

    public slots:
    void createView();

    QQuickView *view;

    #endif // APP_H

    #include "app.h"

    int main(int argc, char *argv[])
    App app(argc, argv);
    return app.exec();

  • Moderators


    I can't tell immediately what the problem is, but why are you subclassing QGuiApplication?

  • Thanks. Moving the QGuiApplication to main.cpp and removing it from the App class resolved the problem.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.