Ensure the UTF-8 string for a xcb_keycode_t has the correct length.
On my platform (Archlinux, libxcb 1.11-1) and a recent build of Qt dev I noticed that writing anything to a QLineEdit was broken, as not only the character for the pressed key was inserted, but also what looks like whitespace. A simple debug program showed that a "\u0000" is appended to every character in the QString text associated with a QKeyEvent, which brought me to QXcbKeyboard::lookupString. The QByteArray to QString conversion using QString::fromUtf8 includes the \x00 byte at the end of the buffer. By leveraging the size returned by the xcb API and passing that to QString::fromUtf8 we can prevent this problem from arising. Change-Id: Ic1d4390e4154e9ed729cd23286811d6eecdf54f6 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>bb10
parent
a7303e45db
commit
7f82b9258e
|
|
@ -1518,8 +1518,8 @@ QString QXcbKeyboard::lookupString(struct xkb_state *state, xcb_keycode_t code)
|
|||
QByteArray chars;
|
||||
chars.resize(1 + xkb_state_key_get_utf8(state, code, 0, 0));
|
||||
// equivalent of XLookupString
|
||||
xkb_state_key_get_utf8(state, code, chars.data(), chars.size());
|
||||
return QString::fromUtf8(chars);
|
||||
const int size = xkb_state_key_get_utf8(state, code, chars.data(), chars.size());
|
||||
return QString::fromUtf8(chars.constData(), size);
|
||||
}
|
||||
|
||||
void QXcbKeyboard::handleKeyPressEvent(const xcb_key_press_event_t *event)
|
||||
|
|
|
|||
Loading…
Reference in New Issue