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. Accessing the ApplicationWindow from other QML files
Forum Updated to NodeBB v4.3 + New Features

Accessing the ApplicationWindow from other QML files

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 665 Views
  • 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.
  • V Offline
    V Offline
    VFCraig
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      Have you tried using the attached property ApplicationWindow.window?

      1 Reply Last reply
      1
      • V Offline
        V Offline
        VFCraig
        wrote on last edited by
        #3

        Yes, no help there either.

        1 Reply Last reply
        0
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          1

          • Login

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