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. How to import a QML file from a different Directory
QtWS25 Last Chance

How to import a QML file from a different Directory

Scheduled Pinned Locked Moved Solved QML and Qt Quick
import
5 Posts 4 Posters 4.1k 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.
  • A Offline
    A Offline
    Anita
    wrote on 7 May 2019, 11:40 last edited by
    #1

    I'am trying to use a qml in a different directory than my project directory.
    The QT editor is recognises the qml. and Build is successful.
    During runtime, there is an error message stating it cannot find the file.

    Directory Flow
    Test
    - test.qml
    MainApp
    -main.qml
    -mainApp.pro
    -main.cpp

    In Main.qml, I am importing test.qml as
    import "../Test/" , the path is not being recognised during runtime.

    Can you please suggest me a solution for this.?

    R J 2 Replies Last reply 7 May 2019, 11:58
    0
    • A Anita
      7 May 2019, 11:40

      I'am trying to use a qml in a different directory than my project directory.
      The QT editor is recognises the qml. and Build is successful.
      During runtime, there is an error message stating it cannot find the file.

      Directory Flow
      Test
      - test.qml
      MainApp
      -main.qml
      -mainApp.pro
      -main.cpp

      In Main.qml, I am importing test.qml as
      import "../Test/" , the path is not being recognised during runtime.

      Can you please suggest me a solution for this.?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 7 May 2019, 11:58 last edited by raven-worx 5 Jul 2019, 12:10
      #2

      @Anita
      the import url is resovled from the base url the qml file was loaded from.
      Are we talking about qrc or file paths here?
      If MainApp/main.qml was loaded via qrc, then there Test/test.qml must also be available within qrc.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • A Anita
        7 May 2019, 11:40

        I'am trying to use a qml in a different directory than my project directory.
        The QT editor is recognises the qml. and Build is successful.
        During runtime, there is an error message stating it cannot find the file.

        Directory Flow
        Test
        - test.qml
        MainApp
        -main.qml
        -mainApp.pro
        -main.cpp

        In Main.qml, I am importing test.qml as
        import "../Test/" , the path is not being recognised during runtime.

        Can you please suggest me a solution for this.?

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 7 May 2019, 12:11 last edited by J.Hilk 5 Jul 2019, 12:15
        #3

        @Anita
        you can take a look at my struggle with this:
        https://forum.qt.io/topic/98165/import-with-relative-path

        Could be helpful

        the actual correct way to handle this correctly would be via your own qml module:
        http://doc.qt.io/qt-5/qtqml-modules-topic.html

        or as a plugin:
        http://doc.qt.io/qt-5/qqmlextensionplugin.html

        But I don't know more about it. That's as far as I got before something else came along with more priority x)


        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
        3
        • A Offline
          A Offline
          Adithya
          wrote on 13 Jun 2019, 10:56 last edited by
          #4

          You can use alias in the qrc file to have all the files in a single directory so that you can use them directly or else you can import the qml stuffs by using import statement (make sure you give the correct path of the file)

          1 Reply Last reply
          1
          • A Offline
            A Offline
            Anita
            wrote on 20 Jun 2019, 05:37 last edited by
            #5

            @raven-worx , @J-Hilk
            Thanks For the solution. It is working by importing the qml as "qrc:/../Test/ in main.qml.

            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