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. QML text inpu to another QML text
Forum Updated to NodeBB v4.3 + New Features

QML text inpu to another QML text

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 3.9k 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.
  • J Offline
    J Offline
    jr_jags
    wrote on last edited by
    #1

    I have 2 Qml's, QML1 contains a textinput where you can write texts, on QML2 i have a text

    Q> How can i show the written text in qml1 to qml2?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      Again when you say qml1 and qml2, are they different views, or just elements in a given view. If you can post some code with what you want to do, it will be easy..

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jr_jags
        wrote on last edited by
        #3

        qml2 is a new screen

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jr_jags
          wrote on last edited by
          #4

          @//this is QML1
          Rectangle {
          width: 360
          height: 360

          Loader {
          id: mainLoader
          anchors.fill: parent
          
          TextInput {
              id: text_input1
              x: 117
              y: 104
              width: 183
              height: 35
              text: ""
              font.bold: true
              font.pixelSize: 19
          }
          
          MouseArea {
              id: ok
              x: 124
              y: 184
              width: 100
              height: 89
              onClicked:  { mainLoader.source = "main2.qml";}
          }
          
          Text {
              id: text1
              x: 158
              y: 215
              width: 80
              height: 20
              text: "OK"
              font.bold: true
              font.pixelSize: 22
          }
          

          }

          Text {
          id: text2
          x: 23
          y: 116
          width: 80
          height: 20
          text: "Write here:"
          font.bold: true
          font.pixelSize: 14
          }
          }
          @

          @import QtQuick 1.0

          //this QML2

          Rectangle {
          width: 340
          height: 399

          Text {
              id: text1
              x: 16
              y: 124
              width: 80
              height: 20
              text: "The text i wrote from QML1:"
              font.bold: true
              font.pixelSize: 19
          }
          
          Text {
              id: textpreview
              x: 150
              y: 177
              width: 89
              height: 47
              text: "text"
              font.bold: true
              font.pixelSize: 20
          }
          

          }
          @

          When i pressed the mousearea ok, the text written in qml1 will be previwed automatically in qml2

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thisisbhaskar
            wrote on last edited by
            #5

            This is how it can be done

            main.qml
            @import QtQuick 1.0

            Rectangle {
            id: mainView
            anchors.fill : parent
            QML1 {
            id:qml1
            anchors.fill: parent
            }
            }
            @

            QML1.qml
            @import QtQuick 1.0

            //this is QML1
            Rectangle {
            width: 360
            height: 360

            Loader {
                id: mainLoader
                anchors.fill: parent
                
                TextInput {
                    id: text_input1
                    x: 117
                    y: 104
                    width: 183
                    height: 35
                    text: ""
                    font.bold: true
                    font.pixelSize: 19
                }
                
                MouseArea {
                    id: ok
                    x: 124
                    y: 184
                    width: 100
                    height: 89
                    onClicked:  {
                        mainLoader.source = "QML2.qml";
                        mainLoader.item.textPosted(text_input1.text)
                    }
                }
                
                Text {
                    id: text1
                    x: 158
                    y: 215
                    width: 80
                    height: 20
                    text: "OK"
                    font.bold: true
                    font.pixelSize: 22
                }
            }
            
            Text {
                id: text2
                x: 23
                y: 116
                width: 80
                height: 20
                text: "Write here:"
                font.bold: true
                font.pixelSize: 14
            }
            

            }
            @

            QML2.qml
            @import QtQuick 1.0

            //this QML2

            Rectangle {
            width: 340
            height: 399

            signal textPosted(string textFromQml1)
            
            onTextPosted: text1.text = textFromQml1
            Text {
                id: text1
                x: 16
                y: 124
                width: 80
                height: 20
                //text:
                font.bold: true
                font.pixelSize: 19
            }
            
            Text {
                id: textpreview
                x: 150
                y: 177
                width: 89
                height: 47
                text: "text"
                font.bold: true
                font.pixelSize: 20
            }
            

            }
            @

            1 Reply Last reply
            0
            • C Offline
              C Offline
              changsheng230
              wrote on last edited by
              #6

              You can also take the advantages of Connections element:

              QML1.qml
              @import QtQuick 1.0
              //this is QML1
              Rectangle {

              id: qml1Text
              width: 360
              height: 360
              
              signal textPosted(string textFromQml1)
              
              Loader {
                  id: mainLoader
                  anchors.fill: parent
                  TextInput {
                      id: text_input1
                      x: 117
                      y: 104
                      width: 183
                      height: 35
                      text: "sddddddd"
                      font.bold: true
                      font.pixelSize: 19
                  }
              
                  Rectangle {
                      x: 124
                      y: 184
                      width: 100
                      height: 89
                      color: "lightblue"
                  }
                  MouseArea {
                      id: ok
                      x: 124
                      y: 184
                      width: 100
                      height: 89
              
                      onClicked:
                      {
                          mainLoader.source = "QML2.qml";
                          qml1Text.textPosted(text_input1.text)
                      }
                  }
              
                  Text {
                      id: text1
                      x: 158
                      y: 215
                      width: 80
                      height: 20
                      text: "OK"
                      font.bold: true
                      font.pixelSize: 22
                  }
              }
              Text {
                  id: text2
                  x: 23
                  y: 116
                  width: 80
                  height: 20
                  text: "Write here:"
                  font.bold: true
                  font.pixelSize: 14
              }
              

              }
              @

              QML2.qml
              @import QtQuick 1.0
              //this QML2
              Rectangle {
              width: 340
              height: 399
              Connections {
              target: qml1Text
              onTextPosted: text1.text = textFromQml1
              }

              Text {
                  id: text1
                  x: 16
                  y: 124
                  width: 80
                  height: 20
                  //text: "The text i wrote from QML1:"
                  font.bold: true
                  font.pixelSize: 19
              }
              Text {
                  id: textpreview
                  x: 150
                  y: 177
                  width: 89
                  height: 47
                  text: "text"
                  font.bold: true
                  font.pixelSize: 20
              }
              

              }
              @

              Chang Sheng
              常升

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TobbY
                wrote on last edited by
                #7

                thanks from me 2, i am also looking for that snippet

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jr_jags
                  wrote on last edited by
                  #8

                  Thanks ^^

                  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