QML folder structure



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


  • Moderators

    @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 {
    }
    


  • @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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.