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) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);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
{
Q_OBJECTpublic:
explicit cryptsyAPI(QObject *parent = 0);
~cryptsyAPI();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:{
Cryptsy.timedAPIRefresh();
}@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."
-
Hi,
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 :)