Solved Communication between two qml files
-
How can access the id from one qml file to another?
-
@eswar Did you instantiate the QML component present in 2nd file in 1st?
-
This post is deleted! -
@eswar Try using
alias
. Have a look at its docs here. Declare a new alias in Page2.qml and point it toLabel
's text. Then when you instantiatePage2
whereMyTextfield
is you can access the alias defined inPage2
by itsid
. Something like:property alias labelText: lab_carearea.text MyTextfield { id: myTextField } Page2 { id: myPage } //access it when instantiated using id myPage.labelText = myTextField.text
-
@p3c0 still i cannot acess the textfield data from page1.qml to page2.qml. In that i want to display the page1.qml textfield entered data to display in the page2.qml . In the page1.qml contain more than 5 textfield. I need to display the tf _patient name textfield only in the page2.qml.
-
@eswar can you show what you tried ?
-
page1.qml
item{ property alias patientName: tf_patientname.tftext MyTextfield{ id:tf_patientname tfheight: 50 tfwidth: 250 tffontbold: true tfborderradius: 5 tfmaxmiumlength:25 tfplaceholdertext:"" tftextcolor:"#1B7497" tftext:"" } } }
Here 5 textfield like age, weight, dateof birth..I want to pass patient named data only to page2.qml
How can i get the data from page1.qml
i want to update the in listview. -
@eswar So what error do you get when you try this ?
-
I didnt know how to acess data only in page2.qml
if i give like
page1{
label{
text:patientName
}
the textfield are arranged in row layout.error: ReferenceError: patientName is not defined
if i give like this
page1{
}it will show all the same layout of page1 in page2. now i need from patient name text only in the page2..
-
@eswar Here is a small example. I have tried to adapt it to your requirements.
//Page1.qml import QtQuick 2.5 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.3 Item { width: 200; height: 200 ColumnLayout { anchors.fill: parent TextField { Layout.preferredWidth: 200 Layout.preferredHeight: 40 onTextChanged: page2.labelText = text } Page2 { id: page2 } } } //Page2.qml import QtQuick 2.5 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 Item { Layout.preferredWidth: 200 Layout.preferredHeight: 40 property alias labelText: label.text Label { id: label color: "red" } }
Here when user types into the
TextField
the text is transferred to thePage2
'sLabel
viaalias property
. Perhaps you can try to do them same in your code. -
The data is transferred to page1 to page2. In that i have face one problem. The two pages are appear in the tabview. The page2.qml label will be diaplayed in the page1.qml. How can i resolve this problem. I need only the textfield text is transferred to page 2.
-
@eswar I would suggest you to write a scale down version of your application and in that try what I suggested. If you already have then post that minimal complete example so that we can suggest the modifications there. That would be more faster.