Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Please advise how to set the property from qml1 to qml2
Qt 6.11 is out! See what's new in the release blog

Please advise how to set the property from qml1 to qml2

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alvinder
    wrote on last edited by
    #1

    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"
    }
    

    }@@

    1 Reply Last reply
    0
    • C Offline
      C Offline
      coldmund
      wrote on last edited by
      #2

      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);
      }
      }
      }
      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alvinder
        wrote on last edited by
        #3

        Thanks a lot. That worked.

        learned something new today.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved