how to recieve/send text from one qml file to another qml file
Unsolved
QML and Qt Quick
-
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/" } }
-
@p3c0 , i tried this
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 }
error :
qrc:/main.qml:104: TypeError: Type error qrc:/main.qml:104: TypeError: Type error
-
@Qjay
You can get text like this,- Create instance of search.qml means like
Search(this is your search.qml file instance, first latter should be capital of your qml file)
{
id: searchText
}
2 In search.qml file create property like
property alias Name_of_variable(like textOfSearchField): id_of_textfield(search_text.text)- Now wherever you want to use, can do like this.
searchText(id_of_instance).Name_of_variable
You will find exact value as you passed in search.qml file
- Create instance of search.qml means like