SetContextProperty
-
I have to change the value of setContextProperty dynamically.
For example:
I have the following code:
engine.rootContext()->setContextProperty("TestingProperty",testValue);
dynamically i need to change the value of testValue, will that be reflected on TestingProperty?Edit1:
I found a solution to this. I am storing the Address of the QQmlApplicationEngine , and reassigning the contextproperty again when i need a dynamic change. Is that the right way to do it? -
The usual approach is to pass a QObject subclass as context property. Whatever values you need to update can then easily be managed via Q_PROPERTY and QML will pick up those changes automatically.
-
Hi sierdzio,
I have tried with a method of having the stroring the engine address in a QQmlApplictaionEngine variable into a local variable of the class(ApplicationEngine).
and when i have to change the value dynamically, i reassign the value as :
ApplicationEngine->rootContext()->setContextProperty("TestingProperty",testValue_new);It works . But is there any problem in this method?
-
Hi sierdzio,
I have tried with a method of having the stroring the engine address in a QQmlApplictaionEngine variable into a local variable of the class(ApplicationEngine).
and when i have to change the value dynamically, i reassign the value as :
ApplicationEngine->rootContext()->setContextProperty("TestingProperty",testValue_new);It works . But is there any problem in this method?
@Anita said in SetContextProperty:
It works . But is there any problem in this method?
Sounds good to me.