Important: Please read the Qt Code of Conduct -

Setting context property for a QQuickView crashing? [SOLVED]

  • Hey there. So I'm having a problem accessing the functions from a class that inherits QObject in my QMainWindow. Here's the initializer for my MainWindow:

    @MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    QQuickView *view = new QQuickView;
    cryptsyAPI cryptsyInterface;
    view->engine()->rootContext()->setContextProperty("Cryptsy", &cryptsyInterface);


    cryptsyAPI is a class that inherits QObject. Here's the .h file:

    @class cryptsyAPI : public QObject

    explicit cryptsyAPI(QObject *parent = 0);

    public slots:
    void timedAPIRefresh();

    "TimedAPIRefresh" right now only outputs "Hello" to the console with qDebug().
    Everything works and compiles perfectly fine, but when I try to access the function from QML, like so:

    @ onClicked:{

    The program crashes. Any idea why? When I open the crash report in Visual Studio, it says "Unhandled exception at 0x000000006D100432 (Qt5Qml.dll) in Bit-sy.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."

  • Lifetime Qt Champion


    Just an educated guess but cryptsyInterface is destroyed at the end of the constructor so accessing it should trigger the crash.

  • Thank you so much! I had been working on that for several hours when I posted this, I wasn't thinking clearly!

  • Lifetime Qt Champion

    You're welcome !

    If this solves your problem, then please update the thread title prepending [solved] so other forum users may know a solution has been found :)

Log in to reply