How to seperate QML components



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


  • Moderators

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



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


  • Moderators

    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.



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


  • Moderators

    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.



  • i got it, thank you a lot :-)


Log in to reply
 

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