Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to seperate QML components

    QML and Qt Quick
    2
    7
    1063
    Loading More Posts
    • 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
      Abdeljalil last edited by

      i want to seperate the different parts of the GUI, in QtQuick UI project, i can put seperate parts in seperated files, but after using subdirs to categorize qml files code is not working. (i use this project for prototyping purpose)
      and i have no idea how to do that in Qt Quick application project! (and this project for final deployment)
      any help?

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        Please tell us more about the errors you are getting.

        You can include files from other directories in QML like this:
        @
        import "some/other/directory"
        @

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • A
          Abdeljalil last edited by

          i have a subdir called Components
          and i import it like this:
          @import "Components/TopBar.qml"@
          and
          @
          TopBar {
          ...
          }
          @
          but i get
          @"Components/TopBar.qml": no such directory@

          and what about QtQuick Application? how to use seperated components?

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            Do not import files, import directories. Also, make sure the QML files are all available where your application is looking for them (QRC file, or deployment directory).

            [quote]and what about QtQuick Application? how to use seperated components?[/quote]

            I do not understand those questions, please elaborate.

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • A
              Abdeljalil last edited by

              thank you, first one is working now :-)
              and about the second question, i mean when i choose a Qt Quick application in new project wizard, how can i seperate qml components?
              because in this case, main qml file will be used in main.cpp file from resources system, so the first method will not work.

              1 Reply Last reply Reply Quote 0
              • sierdzio
                sierdzio Moderators last edited by

                You can create multiple files and folders inside the resource file. Using Qt resource system has the advantage that you do not need to copy the QML files together with your binary file - the resource is already included into the executable itself.

                But if you don't like that, you can simply remove the resource and change the QML file URL to point to the physical file and it will work - the same as in your first case.

                (Z(:^

                1 Reply Last reply Reply Quote 0
                • A
                  Abdeljalil last edited by

                  i got it, thank you a lot :-)

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post