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] Cannot resolve local file url

[Solved] Cannot resolve local file url

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 4.3k 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.
  • P Offline
    P Offline
    pierssen
    wrote on last edited by
    #1

    I'm trying to load an external QML file dynamically. The following code works when I use a FileDialog to resolve the path:

    @
    var Url = fileDialog.fileUrl;
    console.log(Url.toString()); // qml: file:///C:/Templates/benchmark.qml
    templateLoader.source = Url;
    @

    But when I try to assign the source using a string, I get a "File not found" error:

    @
    var sUrl = "file:///C:/Templates/benchmark.qml";
    templateLoader.source = sUrl;
    @

    This seems to be related to the problem in this discussion: http://qt-project.org/forums/viewthread/19528 but when I try the binding trick it doesn't work. What am I doing wrong?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Try using Qt.resolvedUrl(absolute file name)

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pierssen
        wrote on last edited by
        #3

        I had tried that, but it didn't help:

        @
        var sFilePath = "C:/Templates/benchmark.qml";
        var sUrl = "file:///C:/Templates/benchmark.qml";
        templateLoader.source = Qt.resolvedUrl(sFilePath); // Network error
        templateLoader.source = Qt.resolvedUrl(sUrl); // File not found
        @

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          I'm surprised. Just see my example here. It works perfectly here.

          @Rectangle {
          width: 240
          height: 280;color :"blue"
          Loader {
          id : load
          }
          MouseArea{
          anchors.fill: parent
          onClicked: {
          console.log("pthinks.com")
          load.source = Qt.resolvedUrl("/Users/dheeru/Qt/Training/QML/QtQuickTraining/DynamicObjects/UseLoader/LoaderWithAbosolutePath/TestAbsPath.qml")
          }
          }
          }
          @

          TestAbsPath.qml

          @import QtQuick 2.0

          Rectangle {
          width: 100
          height: 200
          color : "yellow"
          }@

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pierssen
            wrote on last edited by
            #5

            Dumb. Dumb. Dumb. I found a typo in my hard-coded path. It works fine when I actually look at my code.

            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