Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Unexpected behavior of operator= in Qml/JavaScript

$
0
0
I have defined a couple of context variables from C++, something like this: class MyClass : public QObject {    Q_OBJECT    Q_PROPERTY(QString name ...) }; MyClass myVar1, myVar2; QQmlContext *ctxt = m_pMainView->rootContext(); ctxt->setContextProperty("myVar1", &myVar1); ctxt->setContextProperty("myVar2", &myVar2); In JavaScript in Qml, I can assign anything I want to myVar1, I don’t get any errors or warnings, and the value of myVar1 never changes: myVar1 = myVar2; myVar1 = 3.0; myVar1 = "Fred"; Having written my own code to inject variables into JavaScript (in the past, not related to Qt) I can certainly imagine why, but it seems like a bad idea that I don’t get any sort of warning or error. Are there any macros I can insert into MyClass, or anything clever I can do that will make the operator= actually do something? Thanks, Chris

Viewing all articles
Browse latest Browse all 4972

Trending Articles