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



  • 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


  • Moderators

    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 ?



  • 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)


  • Moderators

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



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


  • Moderators

    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.



  • 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



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



  • Hi guys,

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



  • is there a workaround for this issue?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.