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. Import with relative path
QtWS25 Last Chance

Import with relative path

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 3.8k 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.
  • J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 3 Jan 2019, 10:14 last edited by
    #1

    Hello everyone,

    I have some issues with importing QML files from a relative path.

    The QML-Item I want to import is called IconButton and is located in a folder parallel to the one where I try to import it to.

    From the docu I figured I can simply call

    import "../SharedFiles/qml"
    

    and I'm fine.
    QtCreator does indeed recognize IconButton item and correctly alows me access to the properties.

    But when running the Application the page failes to load with this error:

    import "../SharedFiles/qml/": no such directory
    

    when I import it as an absolute path

    import "file:///c/path/to/SharedFiles/qml" as Test
    

    it works. But, that is simply insufficient

    • Qt 5.12, (MSVC)
    • QtC 4.8.0
    • all custom qml-files are also part of the qt-ressource file

    Anyone an idea, what I'm doing wrong?


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 3 Jan 2019, 12:32 last edited by
      #4

      This is inadequately documented. 🙁

      The import statement one has to use is:

      import ":/../SharedFiles/qml"

      I remembered that images from the ressource system need the :/ prefix to be used in QML
      pure luck I tried that one....


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      M 1 Reply Last reply 3 Jan 2019, 12:35
      3
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 3 Jan 2019, 10:23 last edited by
        #2

        Hi
        When you run the app, the exe is in the build folder and hence
        there is no SharedFiles near it ?

        J 1 Reply Last reply 3 Jan 2019, 10:36
        0
        • M mrjj
          3 Jan 2019, 10:23

          Hi
          When you run the app, the exe is in the build folder and hence
          there is no SharedFiles near it ?

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 3 Jan 2019, 10:36 last edited by J.Hilk 1 Mar 2019, 11:03
          #3

          @mrjj potentially, but that's usually where the ressource system comes into play, isn't it?

          0_1546511759059_db073729-369d-4219-a7e6-58c01f78fcb6-image.png


          Edit:
          Maybe it's because this is not a normal application but rather a QtPlugin, that I try to load via QPluginLoader ?
          Because I found this section:
          http://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
          that may or maynot help me here :-)


          Btw, works also fine, if I move the folder inside the project tree and use

          import "SharedFiles/qml"

          I may just end up with a a lot of copies of my qml files :(


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 3 Jan 2019, 12:32 last edited by
            #4

            This is inadequately documented. 🙁

            The import statement one has to use is:

            import ":/../SharedFiles/qml"

            I remembered that images from the ressource system need the :/ prefix to be used in QML
            pure luck I tried that one....


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            M 1 Reply Last reply 3 Jan 2019, 12:35
            3
            • J J.Hilk
              3 Jan 2019, 12:32

              This is inadequately documented. 🙁

              The import statement one has to use is:

              import ":/../SharedFiles/qml"

              I remembered that images from the ressource system need the :/ prefix to be used in QML
              pure luck I tried that one....

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 3 Jan 2019, 12:35 last edited by
              #5

              @J.Hilk
              ah that was why i didnt think you had SharedFiles in a resource file :)
              Good found

              J 1 Reply Last reply 3 Jan 2019, 12:43
              0
              • M mrjj
                3 Jan 2019, 12:35

                @J.Hilk
                ah that was why i didnt think you had SharedFiles in a resource file :)
                Good found

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 3 Jan 2019, 12:43 last edited by
                #6

                @mrjj
                I was in the process of adding a PRE_TARGETDEPS to qmake to copy the shared files from a central location x)

                sadly now QtC is not able to analize the import statement. But the compiler is. And that's more inportant.

                0_1546519296976_36a20516-a0be-4495-9c6f-ed60c83db859-image.png

                You can't simply have your cake and eat it!


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                M 1 Reply Last reply 3 Jan 2019, 13:15
                1
                • J J.Hilk
                  3 Jan 2019, 12:43

                  @mrjj
                  I was in the process of adding a PRE_TARGETDEPS to qmake to copy the shared files from a central location x)

                  sadly now QtC is not able to analize the import statement. But the compiler is. And that's more inportant.

                  0_1546519296976_36a20516-a0be-4495-9c6f-ed60c83db859-image.png

                  You can't simply have your cake and eat it!

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 3 Jan 2019, 13:15 last edited by
                  #7

                  @J.Hilk
                  Hmm, its odd it dont know the :/ syntax when supported.

                  1 Reply Last reply
                  0
                  • JonBJ JonB referenced this topic a day ago

                  1/7

                  3 Jan 2019, 10:14

                  • Login

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