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. [SOLVED] QML Loader: load once, use many
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QML Loader: load once, use many

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.4k 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.
  • B Offline
    B Offline
    bkamps
    wrote on 13 Aug 2012, 13:24 last edited by
    #1

    I have a cpp object that has a visible flag. I also have a QML loader that loads the QML file when the cpp object visible flag is true:

    @
    Loader {
    source: myCppObj.visible ? "BigWindow.qml" : ""
    // Do some cpp/qml bindings
    }
    @

    That is fine, but I want to keep the BigWindow in memory when it was visible once. So I don't want to set the source to "" when myCppObj.visible is false...

    Anybody knows a nice tric to set the source once (when the myCppObj.visible flag is true for the first time) and keep the source untouched when the myCppObj.visible flag is changed?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bkamps
      wrote on 13 Aug 2012, 14:41 last edited by
      #2

      I found a trick:

      @
      Loader {
      id: myLoader
      Binding { target: myLoader; property: "source"; value: "BigWindow.qml"; when: myCppObj.Visible == true}
      }
      @
      This trick will set the source property of loader when myCppObj.visible is true. When it is set to false the source stays the same. Also the loader doesn't reload the BigWindow.qml when it is already set.

      The problem is that the loader cannot find BigWindow.qml anymore. Only when i set the absolute path (for example: /opt/myapp/qml/windows/BigWindow.qml") the loader loads the qml file. But I don't want to use the absolute path, I want to use the relative path (starting from qml directory, like the source property of Loader normally uses)!

      The use of normal source property works, it automatically uses the qml directory :
      @
      Loader
      source: "BigWindow.qml"
      @

      I also tried to set the sourceComponent property of Loader but then I don't see BigWindow and also no error is printed that it cannot find the component/file...

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbrasser
        wrote on 15 Aug 2012, 03:55 last edited by
        #3

        It seems like something is going wrong with URL resolution. If you could create a bug report with the details at http://bugreports.qt-project.org , that would be very helpful. You may be able to work around the issue with something like:

        @
        Loader {
        id: myLoader
        property url bigWindowUrl: "BigWindow.qml"
        Binding {
        target: myLoader
        property: "source"
        value: bigWindowUrl
        when: myCppObj.Visible == true
        }
        }
        @

        (this should force earlier resolution)

        Regards,
        Michael

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bkamps
          wrote on 15 Aug 2012, 06:28 last edited by
          #4

          Thanks, this works!!!

          1 Reply Last reply
          0

          1/4

          13 Aug 2012, 13:24

          • Login

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