Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to make onEditingFinished available to individual TextInput elements reusing a common TextInput

How to make onEditingFinished available to individual TextInput elements reusing a common TextInput

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 2 Posters 2.1k 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.
  • N Offline
    N Offline
    Nelson_Piquet
    wrote on last edited by Nelson_Piquet
    #1

    I am new to QML & Qt. I am trying to make multiple TextInput elements which can send their own text when onEditingFinished is triggered. Following is a TextInput item that I have created in MyTextField.qml:

    MyTextField.qml

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    
    Item {
    
    implicitHeight: 200
    implicitWidth: 1000
    
    property alias inputMethodHints: myTextField.inputMethodHints
    property alias text: myTextField.text
    
    Rectangle {
        anchors.fill: parent
        radius: 40
      }
    
    
    TextInput {
        id: myTextField
        objectName: "myTextField"
        anchors.fill: parent
        verticalAlignment: Text.AlignVCenter
        font.pixelSize: 300
        color: 'white'
    
        signal qmlSignal(string msg)
        onEditingFinished: qmlSignal(text)  //This works
      }
    }
    

    I am trying to use the above TextInput element in another qml file like below:

    SomeOtherPage.qml

    Column {
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.margins: theme.defaultMargin
    
        MyTextField {
            id: textfield1
            objectName: "textfield1"
            anchors.left: parent.left
            anchors.right: parent.right
            text: qsTr("some text")
    
           signal qmlSignal11(string msg)
           onEditingFinished: qmlSignal11(text)  //This doesn't work !!
        }
    
        MyTextField {
            id: textfield2
            objectName: "textfield2"
            anchors.left: parent.left
            anchors.right: parent.right
            text: qsTr("some other text")
    
           signal qmlSignal22(string msg)
           onEditingFinished: qmlSignal22(text)  //This doesn't work !!
        }
    }
    

    InMyTextField blocks, QML doesn't allow me to use onEditingFinished at all. Running the app complains Cannot assign to non-existent property "onEditingFinished"

    If I handle onEditingFinished from the parent TextInput I created, it works fine & sends the signal to my C++ class. But I am trying to use onEditingFinished in textfield1 & textfield2. Qml reports that onEditingFinished property is not available. How I can make onEditingFinished available in textfield1 & textfield2 so that I send the text of each unique textfield I create.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi!

      MyTextItem.qml

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      
      Rectangle {
          id: myTextItem
          radius: 10
          width: 100
          height: 30
      
          signal editingFinished()
      
          TextInput {
              anchors.margins: 5
              anchors.fill: parent
              text: "Hallo"
              onEditingFinished: myTextItem.editingFinished()
          }
      }
      

      main.qml

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Column {
              spacing: 10
              MyTextItem {
                  color: "plum"
                  onEditingFinished: console.log("finished plum")
              }
              MyTextItem {
                  color: "lime"
                  onEditingFinished: console.log("finished lime")
              }
          }
      }
      
      N 1 Reply Last reply
      1
      • ? A Former User

        Hi!

        MyTextItem.qml

        import QtQuick 2.7
        import QtQuick.Controls 2.0
        
        Rectangle {
            id: myTextItem
            radius: 10
            width: 100
            height: 30
        
            signal editingFinished()
        
            TextInput {
                anchors.margins: 5
                anchors.fill: parent
                text: "Hallo"
                onEditingFinished: myTextItem.editingFinished()
            }
        }
        

        main.qml

        import QtQuick 2.7
        import QtQuick.Controls 2.0
        import QtQuick.Layouts 1.0
        
        ApplicationWindow {
            visible: true
            width: 640
            height: 480
            title: qsTr("Hello World")
        
            Column {
                spacing: 10
                MyTextItem {
                    color: "plum"
                    onEditingFinished: console.log("finished plum")
                }
                MyTextItem {
                    color: "lime"
                    onEditingFinished: console.log("finished lime")
                }
            }
        }
        
        N Offline
        N Offline
        Nelson_Piquet
        wrote on last edited by
        #3

        @Wieland thanks a many lot. it works

        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