Import with relative path

  • Moderators

    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?

  • Lifetime Qt Champion

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

  • Moderators

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


    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:
    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 :(

  • Moderators

    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....

  • Lifetime Qt Champion

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

  • Moderators

    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.


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

  • Lifetime Qt Champion

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.