How to make QML applications with multiple files using the same technique as is done with Qt and Widgets?



  • How to make QML applications with multiple files using the same technique as is done with Qt and Widgets?

    I would like to create muitiplas windows to feed a small database as user settings and configurations. but do not know to show in another QML file.

    I am not referring to custom controls like buttons and text ...

    eg

    main.qml

    menu.qml
    newuser.qml
    systemsettings.qml
    about.qml



  • You can use Item and a Loader



  • you can offer me more than that I'm still in the dark



  • I think this page should help you.
    "QML Loader Element":http://harmattan-dev.nokia.com/docs/library/html/qt4/qml-loader.html



  • Hi,

    From a "basic" point of view, each QML file defines a type, and if that type happens to be a visual item with some set dimensions (say, 500x500pix) then you can simply instantiate each one, and set the visible property of each appropriately.

    @
    //main.qml
    Item {
    width: 500
    height: 500

    MyPageOne { // defined in MyPageOne.qml
        id: p1
        anchors.fill: parent
        visible: true
    }
    
    MyPageTwo { // defined in MyPageTwo.qml
        id: p2
        anchors.fill: parent
        visible: false
    }
    
    // then on some event like a button click or whatever...
    function switchView() {
        p1.visible: false
        p2.visible: true
    }
    

    }
    @

    From a "higher level" point of view, most component sets / controls offer the "page stack" and "page" types. You define your types as Page-derived types, and then push/pop pages on/off the pagestack to perform UI navigation.

    There are plenty of examples on the web of this, since it was common in Harmattan for example.

    Cheers,
    Chris.



  • Unlike in C/C++ you don't need to include or import other QML files that are part of your project. You just need to add the extra QML files and you can directly use them as components, since each QML file can only have one root component.

    This is not the case with JS files, you still have to import them. Also the same goes for custom C++ components.



  • OK, thanks for the replies.

    I make large applications, I will not do something great with QML, but will not be small. will have many of user interface screens, maybe 30 ~ 50.

    do not want heavy application.

    Will it consume too much CPU or Memory or will it take to start?


Log in to reply
 

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