How do I refer to the previous QML file after a new one is loaded?
-
I have a main.qml file, which loads (using Loader{}) another QML file mainWindow.qml (from a different file directory).
Now, both these files are ApplicationWindow{} type, but I'd like to convert mainWindow.qml to Item{} type so that everything is loaded into the same application window.
mainWindow.qml has a few properties like header, footer which are not Item{} properties. So I'd like to refer those properties to the main.qml file. How do I do that?
I tried to simply write mainID.header and mainID.footer (where mainID is the id of main.qml file), but it says its a non-existent property.
-
Make sure your
main.qmlconstructs anApplicationWindow- it'sidwill be globally accessible.Regarding
onClosingin particular - if your main window is inmain.qmlthen you should not even try doing anything with it in a subcomponent ;-) If you need to get some information between those components - use signals and slots, or property assignments.I can help you with that but I need more info, like a minimal use-case.
-
So the thing is, I added the
main.qmllater. Hence theidof thatApplicationWindowisn't globally accessible, but theidofmainWindow.qmlis.
Meaning, initially the main QML file of the application wasmainWindow.qml. Then I added another filemain.qmland made that the initial QML file. So now I just wantmainWindow.qmlto just be loaded into the newApplicationWindowas aPageorItem.
I hope you understood what I meant. -
QML code does not remember what it used to be. If you change
main.qmlto be yourApplicationWindow, it will be the application window, and it'sidwill be global.And even if the
idwas not global, it's easy to pass relevant information to other components via properties or signals & slots. Here's a simple example:// main.qml ApplicationWindow { id: mainWindow Component { id: myPage MyPage { } } StackView { id: stack initialItem: myPage onCurrentItemChanged: currentItem.text = "Some text!" } }// MyItem.qml Rectangle { property alias text: centralText.text Text { id: centralText text: "Default" } }