Unsolved 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.
-
Perhaps you should rather use Page component instead of
Item
. -
@sierdzio While that does help a bit, it still leaves a few properties out such as onClosing: etc.
Any idea how I can proceed? -
Make sure your
main.qml
constructs anApplicationWindow
- it'sid
will be globally accessible.Regarding
onClosing
in particular - if your main window is inmain.qml
then 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.qml
later. Hence theid
of thatApplicationWindow
isn't globally accessible, but theid
ofmainWindow.qml
is.
Meaning, initially the main QML file of the application wasmainWindow.qml
. Then I added another filemain.qml
and made that the initial QML file. So now I just wantmainWindow.qml
to just be loaded into the newApplicationWindow
as aPage
orItem
.
I hope you understood what I meant. -
QML code does not remember what it used to be. If you change
main.qml
to be yourApplicationWindow
, it will be the application window, and it'sid
will be global.And even if the
id
was 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" } }
-
Unfortunately, that doesn't seem to work :/
I tried to refer to theid
of the newApplicationWindow
inMyItemq.qml
but it just says that its anon-existent property