How to create and show new QML,in Android



  • import QtQuick 2.5
    import QtQuick.Controls 2.0
    import QtQuick.Window 2.0
    
    Rectangle {
        id:circleFriends
    
    
        Rectangle{
            height: Screen.height
            width: Screen.width
    //        x:circleFriends.width
    
    //        PropertyAnimation on x{
    //            to:0; duration:1000;loops:Animation.Infinite
    //        }
        }
    
    }
    
    

    i want to open new window


  • Moderators

    @THEFree Please elaborate your question.



  • @p3c0 main.qml 's button Click on a button to open a new window

    open this “QML”

    import QtQuick 2.5
    import QtQuick.Controls 2.0
    import QtQuick.Window 2.0
    
    Rectangle {
        id:circleFriends
    
    
        Rectangle{
            height: Screen.height
            width: Screen.width
    //        x:circleFriends.width
    
    //        PropertyAnimation on x{
    //            to:0; duration:1000;loops:Animation.Infinite
    //        }
        }
    
    }
    

  • Moderators

    @THEFree
    Following can be done for dynamic object creation and loading:

    • Qt.createComponent() or Qt.createQmlObject()
      Check this document for more info.
    • Loader

    If you want separate windows you will need to use Window as root object.



  • Maybe you could try using a stackview? http://doc.qt.io/qt-5/qml-qtquick-controls2-stackview.html

    main.qml

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    
    ApplicationWindow {
        visible: true
        width: 500
        height: 500
    
        StackView
        {
            id: stackview
            initialItem:
                Pane
                {
                    Button
                    {
                        text: "Open window"
                        onClicked: stackview.push("qrc:/window.qml")
                    }
                }
        }
    }
    

    window.qml

    import QtQuick 2.0
    import QtQuick.Controls 2.0
    
    Pane {
        Column
        {
            Button
            {
                text: "Close"
                onClicked: stackview.pop()
            }
            Label
            {
                text: "This is an opened window"
            }
        }
    }
    


  • @p3c0

    main.qml open other.qml, I think it should be open。

    Because main.qml can't click,But other.qml can't see, If I click back, mail.qml can click


  • Moderators

    @THEFree

    Because main.qml can't click

    Why it doesn't ? Can you post the code ?



  • @p3c0

    mail.qml

    var component;
    var sprite;
    
    function createSpriteObjects() {
        component = Qt.createComponent("qml/CircleFriends.qml");
        if (component.status == Component.Ready)
            finishCreation();
        else
            component.statusChanged.connect(finishCreation);
    }
    
    function finishCreation() {
        if (component.status == Component.Ready) {
            sprite = component.createObject(mainWindow, {"x": 0, "y": 0});
            if (sprite == null) {
                // Error Handling
                console.log("Error creating object");
            }
        } else if (component.status == Component.Error) {
            // Error Handling
            console.log("Error loading component:", component.errorString());
        }
    }
    
    

    other.qml

    import QtQuick 2.5
    import QtQuick.Controls 2.0
    import QtQuick.Window 2.0
    
    ApplicationWindow {
        id:circleFriends
        height: Screen.height
        width: Screen.width
        visible: true
    
        Rectangle{
              anchors.fill: parent
    //        x:circleFriends.width
    
    //        PropertyAnimation on x{
    //            to:0; duration:1000;loops:Animation.Infinite
    //        }
        }
    
    }
    
    

    PC is ok,android is nothing


  • Moderators

    @THEFree Sorry but I don't see any connection between the 2 QML's. I dont see how you load other.qml in main.qml and also anything related to click.



  • @p3c0 createSpriteObjects()

    The pop-up window is transparent in android


  • Moderators

    @THEFree I think the problem is with multiple windows. I guess android doesn't support it.



  • @p3c0 use StackView is ok,Thank God, thank you


Log in to reply
 

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