Results 1 to 2 of 2

Thread: how to recieve/send text from one qml file to another qml file

  1. #1
    Join Date
    Jul 2016
    Posts
    26
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Question how to recieve/send text from one qml file to another qml file

    i want to send the textfield text from main.qml to search.qml file

    main.qml snippet


    Qt Code:
    1. TextField{
    2. id: search_text
    3. placeholderText: " Search "
    4. width: drawer.width
    5.  
    6.  
    7.  
    8. Image {
    9. id: search_button
    10. anchors.right: search_text.right
    11. anchors.verticalCenter: search_text.verticalCenter
    12. source: "qrc:/images/search.png"
    13. MouseArea{
    14. anchors.fill: search_button
    15. onClicked: {
    16. loader.source = "qrc:/pages/search.qml"
    17. stackView.push(loader.item)
    18. listView.currentIndex = -1
    19. }
    20.  
    21.  
    22.  
    23. }
    24. }
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 


    search.qml

    Qt Code:
    1. import QtQuick 2.6
    2. import QtQuick.Controls 2.0
    3. import QtWebView 1.1
    4.  
    5. Pane {
    6. id: pane
    7.  
    8.  
    9. // recieve texinput here so that i can construct url
    10.  
    11. WebView{
    12. id:webview
    13. anchors.fill: parent
    14.  
    15. Component.onCompleted: url = "http://en.wikitolearn.org/"
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 


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

    Qt Code:
    1. TextField{
    2. id: search_text
    3. placeholderText: " Search WikiToLearn"
    4. width: drawer.width
    5. onAccepted: {
    6. loader.item.search = search_text.text
    7. loader.source = "qrc:/pages/search.qml"
    8. stackView.push(loader.item)
    9. listView.currentIndex = -1
    10.  
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    but i got error :

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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to recieve/send text from one qml file to another qml file

    You are trying to set the loader item's search property before it exists, i.e. before it is loaded.

    Cheers,
    _

Similar Threads

  1. Replies: 5
    Last Post: 11th April 2015, 07:42
  2. Replies: 2
    Last Post: 28th February 2014, 12:19
  3. Send exe file over QTcpSocket
    By scarecr0w132 in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2013, 23:07
  4. Replies: 1
    Last Post: 7th April 2011, 04:45
  5. how to send file with qt c++?
    By wei243 in forum Qt Programming
    Replies: 5
    Last Post: 3rd March 2007, 09:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.