how to pass the data from main qml to another qml and vise versa.
-
-
No need to add the Text again in side the comp.
Comp1 {
id : obj
aString:"Venki"
}Based on some action inside the main.qml object
just specify obj.aString = "PthinkS" -
thanks worked , but is it possible to access the variables main.qml from Comp1.qml . i mean opposite of above case
-
You can. Not a good practice.
-
Does this old post answer your question? https://forum.qt.io/topic/74407/how-to-enter-different-stackviews/7
This is really very basic understanding about how qml files and objects work, kind of a FAQ.
-
@venkatesh88 said in how to pass the data from main qml to another qml and vise versa.:
but is it possible to access the variables main.qml from Comp1.qml . i mean opposite of above case
Like dheerendra said, not recommended. If you write a component (Comp1) it's better to do it so that it's not dependent of its surroundings. You can actually access the "parent" property from the main level object of your component but then you have the risk of using it in a way which can't be done run time. For example, if you write in your component:
parent.xyzzy = 1
you have to instantiate your component only inside a parent which actually has the property "xyzzy". Otherwise you will get a runtime error. In C++ you would give the "parent" as an argument when you create or use the "component" but there you have compile time type checking.
-
Here's a similar problem and possible answers: https://forum.qt.io/topic/82459/qml-scope-how-to-access-objects
-
@venkatesh88 Hi,
Use a signal from Comp1 to notify the parent that the value has changed and then update it from the parent side.
Also you could use alias instead of redefining properties//Comp1.qml MainItem{ property alias aString: mvalue.text property alias maxValue: maxvalue.text // ... Comp1 definition } //main.qml Window{ .... Comp1{ ... onMaxValueChanged: xxyyzz = maxValue } }
4/8