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. Importing qml
Qt 6.11 is out! See what's new in the release blog

Importing qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 1.0k Views 2 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.
  • A Offline
    A Offline
    Anita
    wrote on last edited by Anita
    #1

    Hi,
    I am having problem with importing of a qml file in another file.

    My folder structure is as follows:
    Project
    -Build
    - SourceProject
    -main.qml
    -qml.qrc
    -ButtonFile.qml
    -Source
    -Widgets
    -PopupWidget
    -Popup.qml

    I want to import ButtonFile.qml in my Popup.qml,
    qml.qrc file is as follows:
    <RCC>
    <qresource prefix="/">
    <file>main.qml</file>
    <file>ButtonFile.qml</file>
    <file>../../Source/Widgets/PopupWidget/Popup.qml</file>
    </qresource>

    So having this as folder structure how do i import ButtonFile.qml in the file Popup.qml?

    J.HilkJ 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Perhaps this will work:

      import ":/"
      // or
      import "qrc://"
      // or
      import "../../.."
      
      // some code
      ButtonFile {
      
      }
      

      Please show your structure in some other way the current list is quite hard to understand.

      (Z(:^

      1 Reply Last reply
      2
      • A Anita

        Hi,
        I am having problem with importing of a qml file in another file.

        My folder structure is as follows:
        Project
        -Build
        - SourceProject
        -main.qml
        -qml.qrc
        -ButtonFile.qml
        -Source
        -Widgets
        -PopupWidget
        -Popup.qml

        I want to import ButtonFile.qml in my Popup.qml,
        qml.qrc file is as follows:
        <RCC>
        <qresource prefix="/">
        <file>main.qml</file>
        <file>ButtonFile.qml</file>
        <file>../../Source/Widgets/PopupWidget/Popup.qml</file>
        </qresource>

        So having this as folder structure how do i import ButtonFile.qml in the file Popup.qml?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        hi @Anita

        from what you wrote, it seems like your Popup.qml inside your project folder is not the one inside your qrc file.

        If you fix your qrc file, you shouldn't have to import anything.


        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
        • A Offline
          A Offline
          Anita
          wrote on last edited by
          #4

          @sierdzio
          I have 2 main folder in my Project : Build and Source.
          The Build Folder Consists of a Folder SourceProject .which contains the files main.qml,qml.qrc, ButtonFile.qml.
          The Source Folder consists of a Folder named Widgets which contains another folder named PopUpWidgets, and PopupWidgets Contains Popup.qml.

          I tried all the three import statements, during runtime it gives an error "no such directory" for all the three import statements.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anita
            wrote on last edited by
            #5

            @J-Hilk

            Popup.qml is not in the same folder as in the main.qml,qml.qrc,buttonfile.qml.
            The file is placed in a different folder than that of the main.qml.

            J.HilkJ 1 Reply Last reply
            0
            • A Anita

              @J-Hilk

              Popup.qml is not in the same folder as in the main.qml,qml.qrc,buttonfile.qml.
              The file is placed in a different folder than that of the main.qml.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Anita

              import "../../Build/SourceProject"


              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
              • A Offline
                A Offline
                Anita
                wrote on last edited by
                #7

                @J-Hilk

                I tried this , during runtime i got an error:
                "../../Build/SourceProject/": no such directory

                I have tried import "qrc:/../../../Build/SourceProject/" as well im getting the same error.

                I changed the path of the buttonFile.qml in qrc file from <file>ButtonWidget.qml</file> to <file>../../Build/SourceProject/ButtonWidget.qml</file> and imported the qml as "qrc:/../../../Build/SourceProject/" it worked.

                Is it necessary for the import path that we mention in the file and the path in qml.qrc file be the same?

                sierdzioS 1 Reply Last reply
                0
                • A Anita

                  @J-Hilk

                  I tried this , during runtime i got an error:
                  "../../Build/SourceProject/": no such directory

                  I have tried import "qrc:/../../../Build/SourceProject/" as well im getting the same error.

                  I changed the path of the buttonFile.qml in qrc file from <file>ButtonWidget.qml</file> to <file>../../Build/SourceProject/ButtonWidget.qml</file> and imported the qml as "qrc:/../../../Build/SourceProject/" it worked.

                  Is it necessary for the import path that we mention in the file and the path in qml.qrc file be the same?

                  sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  @Anita said in Importing qml:

                  Is it necessary for the import path that we mention in the file and the path in qml.qrc file be the same?

                  Yes, unless you create an alias, like this:

                  <file alias="Some_name.qml">long/path/to/file/File.qml</file>
                  

                  The alias can even change the file name and extension (or have no extension at all - but not sure if QML engine will understand it).

                  (Z(:^

                  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