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. QML folder structure
Forum Update on Monday, May 27th 2025

QML folder structure

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 2.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.
  • C Offline
    C Offline
    cboe
    wrote on last edited by
    #1

    I've found some answers to this but it doesn't seem to help me. I have a lot of .qml files and it's just not feasible anymore to have them all in the same folder. Now I've organized them into subfolders, but the files can't be found at runtime. Example

    <RCC>
        <qresource prefix="/">
            <file>Views/main.qml</file>
            <file>Views/Components/Button.qml</file>
        </qresource>
    </RCC>
    

    Just using

    Button {
      ....
    }
    

    in main.qml doesn't seem to work. Now I found the documentation about importing and all but I can't get it to work and the project is so big it takes ages to migrate this.

    Is there no simple way to just have Qt find the qml files without having to do import statements as long as i make the filenames unique?

    Also, since I've upgraded to 5.7.1, all my qml files are suddenly in the Sources folder - is this normal behaviour?

    raven-worxR 1 Reply Last reply
    0
    • C cboe

      I've found some answers to this but it doesn't seem to help me. I have a lot of .qml files and it's just not feasible anymore to have them all in the same folder. Now I've organized them into subfolders, but the files can't be found at runtime. Example

      <RCC>
          <qresource prefix="/">
              <file>Views/main.qml</file>
              <file>Views/Components/Button.qml</file>
          </qresource>
      </RCC>
      

      Just using

      Button {
        ....
      }
      

      in main.qml doesn't seem to work. Now I found the documentation about importing and all but I can't get it to work and the project is so big it takes ages to migrate this.

      Is there no simple way to just have Qt find the qml files without having to do import statements as long as i make the filenames unique?

      Also, since I've upgraded to 5.7.1, all my qml files are suddenly in the Sources folder - is this normal behaviour?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @cboe said in QML folder structure:

      Is there no simple way to just have Qt find the qml files without having to do import statements as long as i make the filenames unique?

      see QQmlEngine::addImportPath()
      alternatively you can also import folders in QML:

      //main.qml
      import "Components"
      
      Button {
      }
      

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

      C 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @cboe said in QML folder structure:

        Is there no simple way to just have Qt find the qml files without having to do import statements as long as i make the filenames unique?

        see QQmlEngine::addImportPath()
        alternatively you can also import folders in QML:

        //main.qml
        import "Components"
        
        Button {
        }
        
        C Offline
        C Offline
        cboe
        wrote on last edited by
        #3

        @raven-worx

        engine.addImportPath("qrc:/Views/Popups/");
        

        doesn't seem to do the trick and I've tried a few more variations... Can you provide an example? If I try to use one of the new items in qml it won't reckognize it. Do I need to add a qmldir file?

        Also, is it normal that the qml files just show up in the Sources folder inside Qt Creator?

        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