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. Qt/QML: TextInput with Keys.onPressed receives only DEL key and not other keys
QtWS25 Last Chance

Qt/QML: TextInput with Keys.onPressed receives only DEL key and not other keys

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 5 Posters 6.7k 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.
  • M Offline
    M Offline
    MagneticCore
    wrote on last edited by
    #1

    Hello

    System: Qt/QML 5.3.1 Android with Windows QtCreator

    In my main QML page, a Loader is used to load a second QML page. This second QML page contains a TextInput with Keys.onPressed. This TextInput receives only the DEL key and not other keys from standard virtual keyboard.

    Important: My second QML is dynamically loaded by the Loader, ie given by loader.source = "MyTextInput.qml"

    How to do to receive all keys in the TextInput/Keys.onPressed event handler?

    MainPage.qml:
    @ApplicationWindow {
    ...
    Loader {
    id: loader
    focus: true
    }
    }@

    MyTextInput.qml:

    @Column {
    ..
    TextInput {
    focus: true
    Keys.priority: Keys.BeforeItem
    Keys.onPressed {
    console.log(event.text);
    }
    }
    }@

    Thank you

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      I just tested the scenario you explained on Android and it works fine. It receives all Keys.
      Can you post the complete code here ?
      Also which Android device you were testing it on ?

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MagneticCore
        wrote on last edited by
        #3

        Hi,

        I simplified my example as follow, but still impossible to receive keys except DEL key by onPressed or onReleased keys handler.
        The device I use for testing is a Samsung Tab 3 8", with Android 4.1.2

        @import QtQuick 2.2
        import QtQuick.Window 2.1
        import QtQuick.Controls 1.2

        ApplicationWindow {
        visible: true
        width: 640
        height: 400

        toolBar: ToolBar {
        Row {
        anchors.fill: parent
        ToolButton {
        text: "Exit"
        onClicked: Qt.quit();
        }
        }
        }

        TextInput {
        width: 200
        height: 40
        focus: true

        Keys.onPressed: {
            console.log("Key="+event.key+" "+event.text);
        }
        Keys.onReleased: {
            console.log("Key="+event.key+" "+event.text);
        }
        

        }
        }@

        On debug screen, the following error is displayed each time a key is pressed on the virtual keyboard:

        W/Qt (26304): kernel\qmetaobject.cpp:1458 (static bool QMetaObject::invokeMethod(QObject*, const char*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument)): QMetaObject::invokeMethod: No such method QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery,QVariant)

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          I misunderstood your question in first place. It is currently not possible to capture using the Virtual Keyboard on mobile platforms.

          157

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MagneticCore
            wrote on last edited by
            #5

            Thank you Dinosaur Breeder,

            Do you have a link that explains this unavailable feature for mobile platforms?
            And there is a plan to add it?

            If no, I will enter an issue in Qt Tracker to ask for it.

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              I actually asked it over the IRC channel. They replied that it was more like a feature request. I'll post the whole conversation

              bq.
              <astregon> Is there a way to get key pressed event for TextInput in Android devices ?
              <astregon> i tried using Keys.onPressed
              <astregon> it just captures del and enter keys
              <astregon> not other keys i.e digits/alphabets
              <lqi_> i guess others are from the virtual keyboard(input method) event instead of keyboard event
              <astregon> lqi, i didn't understand
              <lqi> sry, /s/others/they
              <astregon> i'm using the virtual keyboard
              <astregon> so it Keys event handler doesn't capture it ?
              <astregon> lqi, is it a bug ?
              <lqi> Keys are only for real keyboard
              <lqi> i don't think it's a bug
              <lqi> it's more like a feature request if you want to have
              <astregon> ok, so is there a workaround for it for now ?
              <lqi> not sure yet
              <lqi> perhaps you could ask some qt&android experts
              <astregon> ok.. thanks
              <jpnurmi> astregon: mobile platforms with virtual keyboards & predictive input etc. are a whole different world than good old physical keyboards. there are no key events as such, but the input method is in a "composing" state until it commits the composed content. furthermore, the actual textual content of TextInput doesn't change meanwhile the input method is composing. it just visually shows the currently composed text
              <jpnurmi> i'm not an input method expert, but this is my interpretation of the issue :)
              <astregon> jpnurmi, but then how is it able to capture del and enter ?
              <jpnurmi> astregon: using the input method events as lqi described
              <jpnurmi> i'm not sure what would be the best solution to expose this information to qml, but we certainly need to do it in a way or another
              <jpnurmi> afaik they tried faking key events on ios or android, but it turned out to be a dead end
              <astregon> jpnurmi, Alright, thanks. Hoping it would be implemented as early as possible. I see lot of those questions on forums.

              157

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MagneticCore
                wrote on last edited by
                #7

                Hello,

                I reported a suggestion for this missing feature in QTBUG reports:
                "https://bugreports.qt-project.org/browse/QTBUG-40803":https://bugreports.qt-project.org/browse/QTBUG-40803

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  PauloPina
                  wrote on last edited by
                  #8

                  Hello,

                  The reported error is occurring using physical keyboard at Android too.

                  I also have verified that none QML objects is getting Active Focus at Android Devices and so does not catch the KeyPress events.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    Geraud
                    wrote on last edited by
                    #9

                    Hi guys,

                    As I am currently facing that issue, is there any new developments there?
                    Or ways to circumvent the issue?

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Tiresias
                      wrote on last edited by
                      #10

                      is there a workaround for this issue?

                      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