macOS: Don't assume NSEvent charactersByApplyingModifiers: produces character

In cases where the keyboard layout doesn't have a mapping for a given
event and modifier combination the result will be an empty string.

Fixes: QTBUG-90683
Pick-to: 6.0
Change-Id: Ice06241f0ae71a19cde041410818decc312bc630
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
bb10
Tor Arne Vestbø 2021-01-27 18:40:12 +01:00
parent 6faa33192c
commit 7c85a45fde
1 changed files with 5 additions and 2 deletions

View File

@ -523,8 +523,11 @@ const QAppleKeyMapper::KeyMap &QAppleKeyMapper::keyMapForKey(VirtualKeyCode virt
// compare the results to Cocoa.
auto cocoaModifiers = toCocoaModifiers(qtModifiers);
auto *charactersWithModifiers = [NSApp.currentEvent charactersByApplyingModifiers:cocoaModifiers];
Q_ASSERT(charactersWithModifiers && charactersWithModifiers.length > 0);
auto cocoaUnicodeKey = QChar([charactersWithModifiers characterAtIndex:0]);
QChar cocoaUnicodeKey;
if (charactersWithModifiers.length > 0)
cocoaUnicodeKey = QChar([charactersWithModifiers characterAtIndex:0]);
if (cocoaUnicodeKey != carbonUnicodeKey) {
qCWarning(lcQpaKeyMapper) << "Mismatch between Cocoa" << cocoaUnicodeKey
<< "and Carbon" << carbonUnicodeKey << "for virtual key" << virtualKey