Skip to content

Commit 4f76792

Browse files
authored
Merge pull request #40 from Shatur95/improve-error-messages
Improve error messages
2 parents c373d83 + 483e073 commit 4f76792

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

QHotkey/qhotkey.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,10 @@ bool QHotkeyPrivate::addShortcutInvoked(QHotkey *hotkey)
279279
QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut;
280280

281281
if(!shortcuts.contains(shortcut)) {
282-
if(!registerShortcut(shortcut))
282+
if(!registerShortcut(shortcut)) {
283+
qCWarning(logQHotkey) << QHotkey::tr("Failed to register %1. Error: %2").arg(hotkey->shortcut().toString(), error);
283284
return false;
285+
}
284286
}
285287

286288
shortcuts.insert(shortcut, hotkey);
@@ -296,9 +298,13 @@ bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey)
296298
return false;
297299
hotkey->_registered = false;
298300
emit hotkey->registeredChanged(true);
299-
if(shortcuts.count(shortcut) == 0)
300-
return unregisterShortcut(shortcut);
301-
else
301+
if(shortcuts.count(shortcut) == 0) {
302+
if (!unregisterShortcut(shortcut)) {
303+
qCWarning(logQHotkey) << QHotkey::tr("Failed to unregister %1. Error: %2").arg(hotkey->shortcut().toString(), error);
304+
return false;
305+
} else
306+
return true;
307+
} else
302308
return true;
303309
}
304310

QHotkey/qhotkey_mac.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ bool QHotkeyPrivateMac::registerShortcut(QHotkey::NativeShortcut shortcut)
227227
0,
228228
&eventRef);
229229
if (status != noErr) {
230-
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
231-
<< status;
230+
error = QString::number(status);
232231
return false;
233232
} else {
234233
this->hotkeyRefs.insert(shortcut, eventRef);
@@ -241,8 +240,7 @@ bool QHotkeyPrivateMac::unregisterShortcut(QHotkey::NativeShortcut shortcut)
241240
EventHotKeyRef eventRef = QHotkeyPrivateMac::hotkeyRefs.value(shortcut);
242241
OSStatus status = UnregisterEventHotKey(eventRef);
243242
if (status != noErr) {
244-
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
245-
<< status;
243+
error = QString::number(status);
246244
return false;
247245
} else {
248246
this->hotkeyRefs.remove(shortcut);

QHotkey/qhotkey_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class QHOTKEY_SHARED_EXPORT QHotkeyPrivate : public QObject, public QAbstractNat
3333
virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
3434
virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
3535

36+
QString error;
37+
3638
private:
3739
QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut> mapping;
3840
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;

QHotkey/qhotkey_win.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ bool QHotkeyPrivateWin::registerShortcut(QHotkey::NativeShortcut shortcut)
267267
if(ok)
268268
return true;
269269
else {
270-
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
271-
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
270+
error = QHotkeyPrivateWin::formatWinError(::GetLastError());
272271
return false;
273272
}
274273
}
@@ -279,8 +278,7 @@ bool QHotkeyPrivateWin::unregisterShortcut(QHotkey::NativeShortcut shortcut)
279278
if(ok)
280279
return true;
281280
else {
282-
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
283-
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
281+
error = QHotkeyPrivateWin::formatWinError(::GetLastError());
284282
return false;
285283
}
286284
}

QHotkey/qhotkey_x11.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
170170
XSync(display, False);
171171

172172
if(errorHandler.hasError) {
173-
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
174-
<< qPrintable(errorHandler.errorString);
173+
error = errorHandler.errorString;
175174
this->unregisterShortcut(shortcut);
176175
return false;
177176
} else
@@ -194,8 +193,7 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
194193
XSync(display, False);
195194

196195
if(errorHandler.hasError) {
197-
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
198-
<< qPrintable(errorHandler.errorString);
196+
error = errorHandler.errorString;
199197
return false;
200198
} else
201199
return true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy