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) :
QQuickView *view = new QQuickView; cryptsyAPI cryptsyInterface; view->engine()->rootContext()->setContextProperty("Cryptsy", &cryptsyInterface); view->setFlags(Qt::Dialog); view->setSource(QUrl("qml/Bit-sy/main.qml"));
cryptsyAPI is a class that inherits QObject. Here's the .h file:
@class cryptsyAPI : public QObject
explicit cryptsyAPI(QObject *parent = 0);
"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:
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."
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!
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 :)