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] Relative URL when creating a reusable QML PageLoader component
Forum Updated to NodeBB v4.3 + New Features

[solved] Relative URL when creating a reusable QML PageLoader component

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.5k 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.
  • P Offline
    P Offline
    prismatic
    wrote on 21 May 2013, 08:33 last edited by
    #1

    Hiya,

    I'm trying to create a PageLoader component for QML. So say I defined a PageLoader.qml file and it has something like the following in it:
    @
    Item
    {
    property var pageStack: [];
    function push(page_url) {}
    function pop() {}

    Loader {
    // do stuff here later
    }
    }
    @

    PageLoader is located along side a bunch of reusable components in /stuff/UIComponents/. A project that's going to use UIComponents is located in /stuff/project/main.qml. In main.qml I call import:

    @
    import QtQuick 2.0
    import "../UIComponents"

    Rectangle {
    PageLoader { id:pageloader; }
    Button { onClicked: pageloader.push("hello.qml"); }
    }
    @

    And this is where I run into trouble. "hello.qml" is intended to be specified relative to "main.qml", because that's where PageLoader has been instantiated. However, PageLoader saves "hello.qml" into its pageStack property and then changes the source of Loader whenever its ready. Loader treats this as a path relative to the component location (in /stuff/uicomponents) and I get an error like:
    @
    /stuff/uicomponents/hello.qml: File not found
    @

    So what am I supposed to do here? How can I pass the right path to my custom component (/stuff/projects/hello.qml) if I want to specify it as a relative path?

    Preet

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prismatic
      wrote on 21 May 2013, 09:14 last edited by
      #2

      Okay, "Qt.resolvedUrl()" ... pretty simple :)
      All that time reading about import paths and it was right here all along
      http://qt-project.org/doc/qt-5.0/qtqml/qml-url.html

      1 Reply Last reply
      0

      1/2

      21 May 2013, 08:33

      • Login

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