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 pass text form QML to Qt
Qt 6.11 is out! See what's new in the release blog

How pass text form QML to Qt

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 1.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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by
    #1

    Hi,

    I test free touch keyboard in QML. It works. please tell me how pass text from keyboard to Qt. Below tested keyboard:

        KeyboardInput {
            label: 'text to send'
            anchors.centerIn: parent
            color: "gray"
            width: 1000
            height: 50
            onAccepted: print('onAccepted', text)
        }
    

    I would like to pass the text variable to qt.

    jsulmJ 1 Reply Last reply
    0
    • D Damian7546

      @jsulm said in How pass text form QML to Qt:

      Do you want to pass the text to C++ part of your application?

      Exactly.
      To better explanation , when I write text in Textinput I get qml: onAccepted exampletext
      and next I would like pass this text to my class in qt.

      But I don't know why is the error:

      qrc:/UI/Accessories/KeyboardController.qml:35:5: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
      qml: onAccepted exampletext
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Damian7546 said in How pass text form QML to Qt:

      class in qt

      Please write "class in C++". QML is also part of Qt.

      Did you read https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Damian7546

        Hi,

        I test free touch keyboard in QML. It works. please tell me how pass text from keyboard to Qt. Below tested keyboard:

            KeyboardInput {
                label: 'text to send'
                anchors.centerIn: parent
                color: "gray"
                width: 1000
                height: 50
                onAccepted: print('onAccepted', text)
            }
        

        I would like to pass the text variable to qt.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Damian7546 said in How pass text form QML to Qt:

        I would like to pass the text variable to qt

        What do you mean?
        Do you want to pass the text to C++ part of your application?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Damian7546 said in How pass text form QML to Qt:

          I would like to pass the text variable to qt

          What do you mean?
          Do you want to pass the text to C++ part of your application?

          D Offline
          D Offline
          Damian7546
          wrote on last edited by Damian7546
          #3

          @jsulm said in How pass text form QML to Qt:

          Do you want to pass the text to C++ part of your application?

          Exactly.
          To better explanation , when I write text in Textinput I get qml: onAccepted exampletext
          and next I would like pass this text to my class in qt.

          But I don't know why is the error:

          qrc:/UI/Accessories/KeyboardController.qml:35:5: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
          qml: onAccepted exampletext
          
          jsulmJ 1 Reply Last reply
          0
          • D Damian7546

            @jsulm said in How pass text form QML to Qt:

            Do you want to pass the text to C++ part of your application?

            Exactly.
            To better explanation , when I write text in Textinput I get qml: onAccepted exampletext
            and next I would like pass this text to my class in qt.

            But I don't know why is the error:

            qrc:/UI/Accessories/KeyboardController.qml:35:5: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
            qml: onAccepted exampletext
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Damian7546 said in How pass text form QML to Qt:

            class in qt

            Please write "class in C++". QML is also part of Qt.

            Did you read https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html ?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Damian7546
              wrote on last edited by Damian7546
              #5

              Thanks for suggestion. It works!

              I wrote class SystemController and generate code from macro Q_PROPERTY(QString text2Print READ text2Print WRITE setText2Print NOTIFY text2PrintChanged)

              and registered my class in qml:
              SystemController { id: systemController }

              Next I change in my .qml code:

              KeyboardInput {
                      label: 'insert text'
                      onAccepted: print('onAccepted', systemController.text2Print = text)
                  }
              

              Can you help me with below error, How can I remove this?

              qrc:/UI/Accessories/KeyboardController.qml:35:5: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
              
              

              Here is a line with a problem:

                  Connections {
                      target: keyboard
                      onAccepted: {
                          root.accepted(text) // emit
                          keyboard.destroy()  // hide
                      }
                      onRejected: keyboard.destroy() // hide
                  }
              
              JoeCFDJ 1 Reply Last reply
              1
              • D Damian7546

                Thanks for suggestion. It works!

                I wrote class SystemController and generate code from macro Q_PROPERTY(QString text2Print READ text2Print WRITE setText2Print NOTIFY text2PrintChanged)

                and registered my class in qml:
                SystemController { id: systemController }

                Next I change in my .qml code:

                KeyboardInput {
                        label: 'insert text'
                        onAccepted: print('onAccepted', systemController.text2Print = text)
                    }
                

                Can you help me with below error, How can I remove this?

                qrc:/UI/Accessories/KeyboardController.qml:35:5: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
                
                

                Here is a line with a problem:

                    Connections {
                        target: keyboard
                        onAccepted: {
                            root.accepted(text) // emit
                            keyboard.destroy()  // hide
                        }
                        onRejected: keyboard.destroy() // hide
                    }
                
                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #6

                @Damian7546 said in How pass text form QML to Qt:

                QML Connections: Implicitly defined onFoo properties in Connections are deprecated

                It is warning, But can you try? Text is not passed to the func explicitly

                        onAccepted(text): {
                            root.accepted(text) // emit
                            keyboard.destroy()  // hide
                        }
                
                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  freedbrt
                  wrote on last edited by
                  #7

                  @Damian7546 said in How pass text form QML to Qt:

                  Can you help me with below error, How can I remove this?

                  Instead of

                  Connections {
                  onAccepted: ...
                  

                  you need to write

                  Connections {
                  function onAccepted(..) { }
                  
                  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