Accessing the ApplicationWindow from other QML files
-
I have an ApplicationWindow declared in main.qml. I have, as the first declared object in it, a Rectangle called, mainView. I need access to mainView across the application.
Oddly, some files seem able to access mainView without any problem, but not all for some reason. And shouldn't it be possible, as ApplicationWindow is suppose to be accessible from any object, to access it as a child of ApplicationWindow with, ApplicationWindow.mainView?
I can't even print out the objectName from the files in question, which is, "MainView". (ApplicationWindow's id is, "rootWindow".)
console.log("parent.data[0].objectName", rootWindow.data[0].objectName)
errors, stating that it cannot resolve the data for an undefined object.
On a stackoverflow page, the following is presented as a way to access ApplicationWindow in other files.
ApplicationWindow
{
id: app
property ApplicationWindow appWindow : app
}and referencing with,
app.<someAppWindowElement>
Still get undefined object from trying to use this as well.
-
Declare a property pointing to your mainView in your ApplicationWindow :
ApplicationWindow { property alias mainView: mainView Rectangle { id: mainView } // ... }
And then access it through the
ApplicationWindow.window
attached property in other files:ApplicationWindow.window.mainView