I have a file called main.qml, which instantiate ApplicationWindow
.
I would like to access this object(app) in other qml file.
ApplicationWindow {
id:app
title: "Title"
visible: true
property int keyboardPosition:10//need to access from other qml files for set/get
....
...
}
Is there any API available to access qml application object?
or
How to set application settings in qml. is it singleton class approach or any other?
ApplicationWindow {
id: app
property ApplicationWindow appWindow : app
}
Then appWindow
will be available to every object nested in the window in the object tree, because of dynamic scoping. So you can appWindow.keyboardPosition
from anywhere. Note that if all you need to access is keyboardPosition
- then you can do that from anywhere as well, as long as it is not overshadowed by another property with the same name up the object tree, you don't need to expose the window object as a property itself.
If you have multiple windows, the property will automatically resolve to the window the current object is in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With