Please advise how to set the property from qml1 to qml2



  • Guys,

    Please help. I am learning from examples.

    Developing on Qt5.2 beta for android.
    Trying to migrate my app from meego to android.

    I am having the problem of the setting the property from qml1 to qml2.

    I was using page when i developed my app in Meego and was able to do it.

    From Qml1.qml when i type qml2. It displays the property but when i try to set it i am getting the following error.

    file:///C:/QTDevelopment/Android/build-Testqml1qml2-Desktop_Qt_5_2_0_MinGW_32bit-Debug/qml/Testqml1qml2/Qml1.qml:22: ReferenceError: qml2 is not defined

    Thanks guys for looking into this.

    Alvinder

    Here is my code
    main.qml

    @@import QtQuick 2.0
    import QtQuick.Controls 1.0

    Rectangle {
    id: appWindow
    width: 600
    height: 480

    TabView {
        id: frame
        anchors.fill: parent
        anchors.margins: Qt.platform.os === "osx" ? 12 : 2
        tabPosition: Qt.BottomEdge
       Tab {
            title: "Qml1"
            Qml1 { id: qml1}
        }
        Tab {
            title: "Qml2"
            Qml2 {id: qml2 }
        }
    }
    

    }@@

    @@
    Qml1.qml

    @@import QtQuick 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0

    Rectangle {
    anchors.fill: parent
    color:"black"

    Text
    {
    id: testtxt
    color:"white"
    text: "This is a test"
    }

    MouseArea {
    id:marea
    anchors.fill: parent
    onClicked: {
    console.log(testtxt.text);

            qml2.testsrt = testtxt.text;
        }
    }
    

    }@@

    Qml2.qml
    @@
    @@import QtQuick 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0

    Rectangle {
    anchors.fill: parent
    property string testsrt

    Text {
        text: testsrt
        color:"black"
    }
    

    }@@



  • Of course, there's no 'qml2' in Qml1.qml. I think you should use signal-slot.
    main.qml
    @
    {
    onSignalToMain(str): qml2.<someId>.text = str;
    }
    @

    Qml1.qml
    @{
    signal signalToMain(string)
    MouseArea{
    onClicked: {
    signalToMain(testtxt.text);
    }
    }
    }
    @



  • Thanks a lot. That worked.

    learned something new today.


Log in to reply
 

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