From 419cf9245a321797393e30fcbb12dff6149295e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 2 Dec 2022 12:37:48 +0100 Subject: [PATCH] Clarify that QKeyEvent::text() may return non-printable characters This is the case for keys such as Qt::Key_Delete ("\u007F"), and Qt::ControlModifier + Qt::Key_C ("\u0003") on Windows and XCB, as well as potentially any key event on macOS when IM is not enabled, as of 705665957baf16f9ec4d256dd4d2fad98788314b. We can not filter QKeyEvent text() based on QChar::isPrint() or similar, as there might e.g. be valid printable text in the private use area, depending on the script and available fonts. See QInputControl::isAcceptableInput() for some of this complexity. Task-number: QTBUG-106393 Change-Id: I84d7ed86f57c1b605ac512d0f7ab66f6a11ed7bb Reviewed-by: Volker Hilsheimer Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/kernel/qevent.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 3e3631f8ca..fe75ec78f7 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1440,12 +1440,13 @@ Q_IMPL_EVENT_COMMON(QKeyEvent) Returns the Unicode text that this key generated. - Return values when modifier keys such as - Shift, Control, Alt, and Meta are pressed - differ among platforms and could return an empty string. + The text is not limited to the printable range of Unicode + code points, and may include control characters or characters + from other Unicode categories, including QChar::Other_PrivateUse. - \note \l key() will always return a valid value, - independent of modifier keys. + The text may also be empty, for example when modifier keys such as + Shift, Control, Alt, and Meta are pressed (depending on the platform). + The key() function will always return a valid value. \sa Qt::WA_KeyCompression */