QML text inpu to another QML text
-
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..
-
@//this is QML1
Rectangle {
width: 360
height: 360Loader { 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: 399Text { 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
-
This is how it can be done
main.qml
@import QtQuick 1.0Rectangle {
id: mainView
anchors.fill : parent
QML1 {
id:qml1
anchors.fill: parent
}
}
@QML1.qml
@import QtQuick 1.0//this is QML1
Rectangle {
width: 360
height: 360Loader { 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: 399signal 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 }
}
@ -
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 }
}
@