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
↧