Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How do I refer to the previous QML file after a new one is loaded?
Forum Updated to NodeBB v4.3 + New Features

How do I refer to the previous QML file after a new one is loaded?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 530 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeDirk_41
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Perhaps you should rather use Page component instead of Item.

      (Z(:^

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LeDirk_41
        wrote on last edited by
        #3

        @sierdzio While that does help a bit, it still leaves a few properties out such as onClosing: etc.
        Any idea how I can proceed?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Make sure your main.qml constructs an ApplicationWindow - it's id will be globally accessible.

          Regarding onClosing in particular - if your main window is in main.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.

          (Z(:^

          1 Reply Last reply
          1
          • L Offline
            L Offline
            LeDirk_41
            wrote on last edited by
            #5

            So the thing is, I added the main.qml later. Hence the id of that ApplicationWindow isn't globally accessible, but the id of mainWindow.qml is.
            Meaning, initially the main QML file of the application was mainWindow.qml. Then I added another file main.qml and made that the initial QML file. So now I just want mainWindow.qml to just be loaded into the new ApplicationWindow as a Page or Item.
            I hope you understood what I meant.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              QML code does not remember what it used to be. If you change main.qml to be your ApplicationWindow, it will be the application window, and it's id 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"
                }
              }
              

              (Z(:^

              1 Reply Last reply
              3
              • L Offline
                L Offline
                LeDirk_41
                wrote on last edited by
                #7

                Unfortunately, that doesn't seem to work :/
                I tried to refer to the id of the new ApplicationWindow in MyItemq.qml but it just says that its a non-existent property

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved