PDA

View Full Version : how to recieve/send text from one qml file to another qml file



arcade
16th July 2016, 07:48
i want to send the textfield text from main.qml to search.qml file

main.qml snippet



TextField{
id: search_text
placeholderText: " Search "
width: drawer.width



Image {
id: search_button
anchors.right: search_text.right
anchors.verticalCenter: search_text.verticalCenter
source: "qrc:/images/search.png"
MouseArea{
anchors.fill: search_button
onClicked: {
loader.source = "qrc:/pages/search.qml"
stackView.push(loader.item)
listView.currentIndex = -1
}



}
}

}


search.qml


import QtQuick 2.6
import QtQuick.Controls 2.0
import QtWebView 1.1

Pane {
id: pane


// recieve texinput here so that i can construct url

WebView{
id:webview
anchors.fill: parent

Component.onCompleted: url = "http://en.wikitolearn.org/"
}
}



what i have tried ( i tried create a property in Search.qml and access this property through Loader.
For eg.


TextField{
id: search_text
placeholderText: " Search WikiToLearn"
width: drawer.width
onAccepted: {
loader.item.search = search_text.text
loader.source = "qrc:/pages/search.qml"
stackView.push(loader.item)
listView.currentIndex = -1


}

but i got error :

qrc:/main.qml:104: TypeError: Type error
qrc:/main.qml:104: TypeError: Type error

anda_skoa
16th July 2016, 11:50
You are trying to set the loader item's search property before it exists, i.e. before it is loaded.

Cheers,
_