mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
logging update
use QLoggingCategory now to provides improved logging
This commit is contained in:
@@ -40,6 +40,8 @@ private slots:
|
||||
|
||||
void on_threadEnableCheckBox_clicked();
|
||||
|
||||
void on_loggingCheckBox_clicked(bool checked);
|
||||
|
||||
private:
|
||||
Ui::HotTestWidget *ui;
|
||||
|
||||
|
||||
+79
-79
@@ -31,13 +31,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_1"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="hotkeyCheckbox_2">
|
||||
<property name="text">
|
||||
<string>Count:</string>
|
||||
<string>Hotkey &2:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -151,6 +148,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_1"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Count:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QToolButton" name="resetButton_1">
|
||||
<property name="arrowType">
|
||||
@@ -158,23 +165,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="hotkeyCheckbox_2">
|
||||
<property name="text">
|
||||
<string>Hotkey &2:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_2"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Count:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLCDNumber" name="hotkeyCount_2">
|
||||
<property name="enabled">
|
||||
@@ -285,13 +275,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QToolButton" name="resetButton_2">
|
||||
<property name="arrowType">
|
||||
<enum>Qt::LeftArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="hotkeyCheckbox_3">
|
||||
<property name="text">
|
||||
@@ -299,16 +282,33 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_3"/>
|
||||
<item row="1" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_2"/>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Count:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QToolButton" name="resetButton_2">
|
||||
<property name="arrowType">
|
||||
<enum>Qt::LeftArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="hotkeyCheckbox_4">
|
||||
<property name="text">
|
||||
<string>Hotkey &4:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_3"/>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLCDNumber" name="hotkeyCount_3">
|
||||
<property name="enabled">
|
||||
@@ -419,6 +419,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Count:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QToolButton" name="resetButton_3">
|
||||
<property name="arrowType">
|
||||
@@ -426,20 +433,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="hotkeyCheckbox_4">
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Hotkey &4:</string>
|
||||
<string>Count:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_4"/>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Count:</string>
|
||||
<item row="3" column="4">
|
||||
<widget class="QToolButton" name="resetButton_4">
|
||||
<property name="arrowType">
|
||||
<enum>Qt::LeftArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -553,13 +560,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="4">
|
||||
<widget class="QToolButton" name="resetButton_4">
|
||||
<property name="arrowType">
|
||||
<enum>Qt::LeftArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="hotkeyCheckbox_5">
|
||||
<property name="text">
|
||||
@@ -567,8 +567,31 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_5"/>
|
||||
<item row="5" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>41</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>41</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
@@ -694,31 +717,8 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>41</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>41</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<item row="4" column="1">
|
||||
<widget class="QKeySequenceEdit" name="hotkeySequenceEdit_5"/>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<spacer name="verticalSpacer_3">
|
||||
@@ -733,8 +733,8 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="3">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<item row="5" column="4">
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
@@ -746,8 +746,8 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="4">
|
||||
<spacer name="verticalSpacer_5">
|
||||
<item row="5" column="3">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
|
||||
+6
-7
@@ -6,6 +6,8 @@
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
|
||||
Q_LOGGING_CATEGORY(logQHotkey, "[QHotkey]")
|
||||
|
||||
QHotkey::QHotkey(QObject *parent) :
|
||||
QObject(parent),
|
||||
key(Qt::Key_unknown),
|
||||
@@ -65,7 +67,7 @@ bool QHotkey::setShortcut(const QKeySequence &shortcut, bool autoRegister)
|
||||
if(shortcut.isEmpty()) {
|
||||
return this->resetShortcut();
|
||||
} else if(shortcut.count() > 1) {
|
||||
qWarning("QHotkey: Keysequences with multiple shortcuts are not allowed! "
|
||||
qCWarning(logQHotkey, "Keysequences with multiple shortcuts are not allowed! "
|
||||
"Only the first shortcut will be used!");
|
||||
}
|
||||
|
||||
@@ -80,11 +82,9 @@ bool QHotkey::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool aut
|
||||
if(autoRegister) {
|
||||
if(!QHotkeyPrivate::instance()->removeShortcut(this))
|
||||
return false;
|
||||
} else {
|
||||
qWarning("QHotkey: Can't change the shortcut while the hotkey is registered");
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this->key = key;
|
||||
this->mods = modifiers;
|
||||
@@ -95,7 +95,7 @@ bool QHotkey::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool aut
|
||||
else
|
||||
return true;
|
||||
} else {
|
||||
qWarning() << "QHotkey: Unable to map shortcut to native keys. Key:" << key << "Modifiers:" << modifiers;
|
||||
qCWarning(logQHotkey) << "Unable to map shortcut to native keys. Key:" << key << "Modifiers:" << modifiers;
|
||||
this->key = Qt::Key_unknown;
|
||||
this->mods = Qt::NoModifier;
|
||||
this->nativeShortcut = NativeShortcut();
|
||||
@@ -107,7 +107,6 @@ bool QHotkey::resetShortcut()
|
||||
{
|
||||
if(this->registered &&
|
||||
!QHotkeyPrivate::instance()->removeShortcut(this)) {
|
||||
qWarning("QHotkey: Failed to unregister shortcut");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -144,7 +143,7 @@ QHotkeyPrivate::QHotkeyPrivate() :
|
||||
QHotkeyPrivate::~QHotkeyPrivate()
|
||||
{
|
||||
if(!this->shortcuts.isEmpty())
|
||||
qWarning("QHotkey: QHotkeyPrivate destroyed with registered shortcuts!");
|
||||
qCWarning(logQHotkey, "QHotkeyPrivate destroyed with registered shortcuts!");
|
||||
if(qApp && qApp->eventDispatcher())
|
||||
qApp->eventDispatcher()->removeNativeEventFilter(this);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QKeySequence>
|
||||
#include <QPair>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
class QHotkey : public QObject
|
||||
{
|
||||
@@ -48,4 +49,6 @@ private:
|
||||
bool registered;
|
||||
};
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(logQHotkey)
|
||||
|
||||
#endif // QHOTKEY_H
|
||||
|
||||
@@ -207,7 +207,8 @@ bool QHotkeyPrivateMac::registerShortcut(QHotkey::NativeShortcut shortcut)
|
||||
0,
|
||||
&eventRef);
|
||||
if (status != noErr) {
|
||||
qWarning() << "QHotkey: Failed to register hotkey. Error:" << status;
|
||||
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
|
||||
<< status;
|
||||
return false;
|
||||
} else {
|
||||
this->hotkeyRefs.insert(shortcut, eventRef);
|
||||
@@ -220,7 +221,8 @@ bool QHotkeyPrivateMac::unregisterShortcut(QHotkey::NativeShortcut shortcut)
|
||||
EventHotKeyRef eventRef = QHotkeyPrivateMac::hotkeyRefs.value(shortcut);
|
||||
OSStatus status = UnregisterEventHotKey(eventRef);
|
||||
if (status != noErr) {
|
||||
qWarning() << "QHotkey: Failed to unregister hotkey. Error:" << status;
|
||||
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
||||
<< status;
|
||||
return false;
|
||||
} else {
|
||||
this->hotkeyRefs.remove(shortcut);
|
||||
|
||||
@@ -228,7 +228,8 @@ bool QHotkeyPrivateWin::registerShortcut(QHotkey::NativeShortcut shortcut)
|
||||
if(ok)
|
||||
return true;
|
||||
else {
|
||||
qWarning() << "QHotkey: Failed to register hotkey. Error:" << qPrintable(formatWinError(::GetLastError()));
|
||||
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
|
||||
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +240,8 @@ bool QHotkeyPrivateWin::unregisterShortcut(QHotkey::NativeShortcut shortcut)
|
||||
if(ok)
|
||||
return true;
|
||||
else {
|
||||
qWarning() << "QHotkey: Failed to unregister hotkey. Error:" << qPrintable(formatWinError(::GetLastError()));
|
||||
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
||||
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ private:
|
||||
HotkeyErrorHandler();
|
||||
~HotkeyErrorHandler();
|
||||
|
||||
static bool hasError;//TODO threading
|
||||
static QString errorString;//TODO threading
|
||||
static bool hasError;
|
||||
static QString errorString;
|
||||
|
||||
private:
|
||||
XErrorHandler prevHandler;
|
||||
@@ -108,7 +108,8 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
|
||||
}
|
||||
|
||||
if(errorHandler.hasError) {
|
||||
qWarning() << "QHotkey: Failed to register hotkey. Error:" << qPrintable(errorHandler.errorString);
|
||||
qCWarning(logQHotkey) << "[QHotkey] Failed to register hotkey. Error:"
|
||||
<< qPrintable(errorHandler.errorString);
|
||||
this->unregisterShortcut(shortcut);
|
||||
return false;
|
||||
} else
|
||||
@@ -130,7 +131,8 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
|
||||
}
|
||||
|
||||
if(errorHandler.hasError) {
|
||||
qWarning() << "QHotkey: Failed to unregister hotkey. Error:" << qPrintable(errorHandler.errorString);
|
||||
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
||||
<< qPrintable(errorHandler.errorString);
|
||||
this->unregisterShortcut(shortcut);
|
||||
return false;
|
||||
} else
|
||||
|
||||
@@ -4,7 +4,7 @@ A global shortcut/hotkey for Desktop Qt-Applications.
|
||||
The QHotkey is a class that can be used to create hotkeys/global shortcuts, aka shortcuts that work everywhere, independent of the application state. This means your application can be active, inactive, minimized or not visible at all and still receive the shortcuts.
|
||||
|
||||
## Status
|
||||
**Still in development!!!** - But almost done. There are only some small details, like debug output, and documentation left. It's ready to be used.
|
||||
**Still in development!!!** - But almost done. There are only some small details and documentation left. It's ready to be used.
|
||||
|
||||
## Features
|
||||
- Works on Windows, Mac and X11
|
||||
@@ -48,6 +48,13 @@ By running the example in `./HotkeyTest` you can test out the QHotkey class. The
|
||||
- **Testings:** A list of selected hotkeys. Activate it and try out which ones work for you (*Hint:* Depending on OS and keyboard layout, it's very possible that a few don't work).
|
||||
- **Threading:** Activate the checkbox to move 2 Hotkeys of the playground to seperate threads. It should work without a difference.
|
||||
|
||||
### Logging
|
||||
By default, QHotkey prints some warning messages if something goes wrong (For example, a key that cannot be translated). All messages of QHotkey are grouped into the [`QLoggingCategory`](https://doc.qt.io/qt-5/qloggingcategory.html) "[QHotkey]". If you want to simply disable the logging, call the folling function somewhere in your code:
|
||||
```cpp
|
||||
QLoggingCategory::setFilterRules(QStringLiteral("[QHotkey].warning=false"));
|
||||
```
|
||||
This will turn all warnings of QHotkey of (It only uses warnings for now, thats why this is enough). For more information about all the things you can do with the logging categories, check the Qt-Documentation
|
||||
|
||||
## Thread saftey
|
||||
The QHotkey class itself is reentrant - wich means you can create as many instances as required on any thread. This allows you to use the QHotkey on all threads. **But** you should never use the QHotkey instance on a thread that is different from the one the instance belongs to! Internally the system uses a singleton instance that handles the hotkey events and distributes them to the QHotkey instances. This internal class is completley threadsafe.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user