From 8584ff1b1589ffd2c567486e2f3f6219d5e8e4e8 Mon Sep 17 00:00:00 2001 From: Shatur95 Date: Tue, 20 Oct 2020 13:33:22 +0300 Subject: [PATCH] Use QTimer::singleShort https://doc.qt.io/qt-5/qtimer.html#singleShot-4 --- QHotkey/qhotkey_x11.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/QHotkey/qhotkey_x11.cpp b/QHotkey/qhotkey_x11.cpp index 5310a07..e3f8519 100644 --- a/QHotkey/qhotkey_x11.cpp +++ b/QHotkey/qhotkey_x11.cpp @@ -29,7 +29,6 @@ class QHotkeyPrivateX11 : public QHotkeyPrivate private: static const QVector specialModifiers; static const quint32 validModsMask; - QTimer *releaseTimer = nullptr; xcb_key_press_event_t prevHandledEvent; xcb_key_press_event_t prevEvent; @@ -75,17 +74,11 @@ bool QHotkeyPrivateX11::nativeEventFilter(const QByteArray &eventType, void *mes } else if (genericEvent->response_type == XCB_KEY_RELEASE) { xcb_key_release_event_t keyEvent = *static_cast(message); this->prevEvent = keyEvent; - auto *timer = new QTimer(this); - timer->setSingleShot(true); - timer->setInterval(50); - connect(timer, &QTimer::timeout, this, [this, keyEvent, timer] { + QTimer::singleShot(50, [this, keyEvent] { if(this->prevEvent.time == keyEvent.time && this->prevEvent.response_type == keyEvent.response_type && this->prevEvent.detail == keyEvent.detail){ this->releaseShortcut({keyEvent.detail, keyEvent.state & QHotkeyPrivateX11::validModsMask}); } - delete timer; }); - timer->start(); - this->releaseTimer = timer; this->prevHandledEvent = keyEvent; }