#include "Hotkey.h" #include "QHotkey" #include Hotkey::Hotkey(QObject *parent) : QObject{parent} { m_sequence = ""; m_isRegistered = false; connect(this, &Hotkey::sequenceChanged, this, [=] { if (m_hotkey) { delete m_hotkey; m_hotkey = nullptr; } m_hotkey = new QHotkey(QKeySequence(m_sequence), true, qApp); this->isRegistered(m_hotkey->isRegistered()); QObject::connect(m_hotkey, &QHotkey::activated, qApp, [=]() { Q_EMIT this->activated(); }); QObject::connect(m_hotkey, &QHotkey::registeredChanged, qApp, [=]() { this->isRegistered(m_hotkey->isRegistered()); }); }); } Hotkey::~Hotkey() { if (m_hotkey) { delete m_hotkey; m_hotkey = nullptr; } }