Portable QML app using Qt Component



  • Hi all,
    I'd like to use Qt Component in a QML application that I also use in a Linux Desktop.

    The main.qml for Desktop start with:
    @
    import QtQuick 1.1
    Item
    {
    id: window
    signal effettuaLogin(string nome, string password)

    Rectangle {
        id: root
    

    ...
    ...

    @

    while the same main file for N9 should start with:
    @
    import QtQuick 1.1

    import com.nokia.meego 1.1

    PageStackWindow {
    id: window

    signal effettuaLogin(string nome, string password)
    
    Rectangle {
        id: root
    

    ...
    ...
    @

    The problem is that the N9 version doesn't compile for Linux Desktop. This way I must keep two different main file for different platform.

    Is there a way to use the same main for both platform?



  • Not really. You can use a bootstrap main.qml which basically reads a context object property (eg, "isDesktop" or something) which you set in your C++ entrypoint, and based on that value, dynamically loads either one or the other file.

    eg, something like:

    @
    // platform-independent main qml, which loads platform-specific main qml.
    import QtQuick 1.1

    Item {
    Loader {
    id: loader
    }

    Component.onCompleted: {
        if (contextObject.isDesktop) {
            loader.setSource("desktopmain.qml");
        } else {
            loader.setSource("n9main.qml");
        }
    }
    

    }
    @



  • Thanks, I'm trying that...


Log in to reply
 

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