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. How to set textfield data from one page to another page in qml

How to set textfield data from one page to another page in qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 339 Views
  • 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.
  • S Offline
    S Offline
    Srsirsat
    wrote on last edited by
    #1

    Hello,
    I am learning qt. I want to set textfield data of second page from main page. When I set text to textfield of main page, the textfield of second page is also have to set. I have following code structure

    main.qml
    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4

    ApplicationWindow {
    id: root
    visible: true
    width : 400
    height: 300

    StackView {
        id: stack
        initialItem: view
    
        Component {
            id: view
    
            MouseArea {
                Text {
                    text: stack.depth
                    anchors.centerIn: parent
                }
                onClicked: stack.push(view)
            }
        }
    }
    Button {
        id: button
        x: 86
        y: 95
        width: 114
        height: 54
        text: qsTr("Button")
        onClicked: {
           console.debug("New Page")
              stack.pop(StackView.Immediate)
           stack.push (Qt.resolvedUrl("Newalt.qml"))
        }
    }
    TextField{
        id: setText
        text: "ASK"
    }
    

    }

    Newalt.qml
    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4

    Item {
    Label {
    id: label
    x: 249
    y: 166
    width: 138
    height: 58
    text: qsTr("New page")
    font.pointSize: 11
    fontSizeMode: Text.VerticalFit
    verticalAlignment: Text.AlignVCenter

    }
    
    TextField{
    id: getText
    text: ""
    }
    

    }

    D 1 Reply Last reply
    0
    • S Srsirsat

      Hello,
      I am learning qt. I want to set textfield data of second page from main page. When I set text to textfield of main page, the textfield of second page is also have to set. I have following code structure

      main.qml
      import QtQuick 2.3
      import QtQuick.Window 2.2
      import QtQuick.Controls 1.4

      ApplicationWindow {
      id: root
      visible: true
      width : 400
      height: 300

      StackView {
          id: stack
          initialItem: view
      
          Component {
              id: view
      
              MouseArea {
                  Text {
                      text: stack.depth
                      anchors.centerIn: parent
                  }
                  onClicked: stack.push(view)
              }
          }
      }
      Button {
          id: button
          x: 86
          y: 95
          width: 114
          height: 54
          text: qsTr("Button")
          onClicked: {
             console.debug("New Page")
                stack.pop(StackView.Immediate)
             stack.push (Qt.resolvedUrl("Newalt.qml"))
          }
      }
      TextField{
          id: setText
          text: "ASK"
      }
      

      }

      Newalt.qml
      import QtQuick 2.3
      import QtQuick.Window 2.2
      import QtQuick.Controls 1.4

      Item {
      Label {
      id: label
      x: 249
      y: 166
      width: 138
      height: 58
      text: qsTr("New page")
      font.pointSize: 11
      fontSizeMode: Text.VerticalFit
      verticalAlignment: Text.AlignVCenter

      }
      
      TextField{
      id: getText
      text: ""
      }
      

      }

      D Offline
      D Offline
      DavidM29
      wrote on last edited by DavidM29
      #2

      @Srsirsat

      I don't know if it what you want but, put a property in your Newalt.qml then when you do the stack.push add the property with the value of the setText.text see the following example :

      main.qml :

      import QtQuick 2.3
      import QtQuick.Window 2.2
      import QtQuick.Controls 1.4
      
      ApplicationWindow {
          id: root
          visible: true
          width : 400
          height: 300
      
          StackView {
              id: stack
              initialItem: view
      
              Component {
                  id: view
      
                  MouseArea {
                      Text {
                          text: stack.depth
                          anchors.centerIn: parent
                      }
                      onClicked: stack.push(view)
                  }
              }
          }
          Button {
              id: button
              x: 86
              y: 95
              width: 114
              height: 54
              text: qsTr("Button")
              onClicked: {
                  console.debug("New Page")
                  stack.pop(StackView.Immediate)
                  stack.push ({item: Qt.resolvedUrl("Newalt.qml"), properties: {textToSet: setText.text}}) //Push with the property value
              }
          }
          TextField{
              id: setText
              text: "ASK"
          }
      
      }
      
      

      Newalt.qml :

      import QtQuick 2.3
      import QtQuick.Window 2.2
      import QtQuick.Controls 1.4
      
      Item {
          property string textToSet: "New page"
          Label {
              id: label
              x: 249
              y: 166
              width: 138
              height: 58
              text: qsTr("New Page")
              font.pointSize: 11
              fontSizeMode: Text.VerticalFit
              verticalAlignment: Text.AlignVCenter
      
          }
      
          TextField{
              id: getText
              text: textToSet
              anchors.top: label.bottom
              anchors.left: label.left
          }
      
      }
      
      
      
      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