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 seperate QML components
QtWS25 Last Chance

How to seperate QML components

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 1.4k 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
    Abdeljalil
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

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

        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
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

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

            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
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

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

                i got it, thank you a lot :-)

                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