Important: Please read the Qt Code of Conduct -

Deployment of different QML files

  • I have two QML files of same project. The UI apperance of two files are different based on mobile and desktop machine. If i select the desktop deployment, the one QML file will be deployed. If I choose Android deployment, the another file will be loaded in the loader. How i can choose QML file based on the deployment of target platform?

  • Moderators

    @eswar You can make use of the platform object.
    Check this.

  • @eswar you can also use QQmlFileSelector

  • @p3c0 @literA2

    Thanks for your reply

    I go through the QQmlfileselector. But i can't understand, how to implement in main file. Please provide the links or example related to this topic.

  • hi @eswar

    To implement it in your main.cpp file, you just need to create a new instance of QQmlFileSelector.

    new QQmlFileSelector(QQmlEngine);

    Then, your data directory should be like this:

    qml/+android/File.qml   //this file will be called if you are compiling in Android
    qml/File.qml            //this is your base file which will be used when in Desktop

    In your qml files, you just have to call File{}, qml will automatically call the correct file to instantiate.
    Please be reminded that both files should have the same properties, even if it is not being used by the other.

    hope this will help.

Log in to reply