Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Change child windows element text or proporty

    QML and Qt Quick
    3
    4
    726
    Loading More Posts
    • 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.
    • mehmetak
      mehmetak last edited by

      hi i have two qml file . one of them main.qml and other file users.qml
      i can access users.title with command ornektext.text = userScreen.title
      but i cant access id:username text.
      how can change username id text ?

      @
      main.qml

      import QtQuick 2.3
      import QtQuick.Controls 1.2
      import QtQuick.Layouts 1.0
      import QtQuick.Dialogs 1.0
      import "content"
      ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("Adres Kayıt Ekranı")
      ChildWindow { id: window1 }
      Users { id:userScreen }
      menuBar: MenuBar {
      Menu {
      title: qsTr("Adress")
      MenuItem {
      text: qsTr("&Open")
      onTriggered: console.log("Open action triggered");
      }
      MenuItem {
      text: qsTr("Exit")
      onTriggered: Qt.quit();
      }
      }
      Menu {
      title: "More Stuff"
      MenuItem {
      text: "Do Nothing"
      onTriggered: window1.visible = !window1.visible
      }
      MenuItem {
      text: "Yeni bir pencere aç "
      onTriggered: {
      userScreen.visible = !userScreen.visible
      ornektext.text = userScreen.title
      }
      .....
      .....
      ...
      users.qml

      import QtQuick 2.2
      import QtQuick.Window 2.1
      import QtQuick.Controls 1.2
      Window {
      id:userScreen
      width: 400
      height: 400
      title: "Kullanıcı Ekranı"
      Rectangle {
      id:cerceve
      width: 400
      height: 62
      Text
      {
      id:username
      text:qsTr("Mehmet")
      }
      }
      }
      @

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        Hi and Welcome,

        Create a property in users.qml, bind it to username's text and then access this property from main.qml.
        Also please keep indentation in code so that its easier for others to read.

        157

        1 Reply Last reply Reply Quote 0
        • sierdzio
          sierdzio Moderators last edited by

          The scope of all "ids" in QML is local file. They are not visible outside a file. So you need to export your text as a property:
          @
          proerty string text: "something"
          // ...
          Text
          {
          id:username
          text: userScreen.text
          }

          // And to access it in main:
          userScreen.text
          @

          (Z(:^

          1 Reply Last reply Reply Quote 0
          • mehmetak
            mehmetak last edited by

            thx sierdzio , thx p3c0

            i solved problem.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post