Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to recieve/send text from one qml file to another qml file
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmltextinputtextdataqt 5.7
4 Posts 3 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QjayQ Offline
    QjayQ Offline
    Qjay
    wrote on last edited by
    #1

    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/"
        }
    }
    
    
    p3c0P 1 Reply Last reply
    0
    • QjayQ Qjay

      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/"
          }
      }
      
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      @Qjay You can create a property in Search.qml and access this property through Loader.
      For eg.

      loader.item.myProperty //myProperty is defined in Search.qml
      

      157

      1 Reply Last reply
      0
      • QjayQ Offline
        QjayQ Offline
        Qjay
        wrote on last edited by Qjay
        #3

        @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
        
        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vicky Sharma
          wrote on last edited by Vicky Sharma
          #4

          @Qjay
          You can get text like this,

          1. 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)

          1. 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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved