shutdown thread fail repaired (test)

This commit is contained in:
Skycoder42
2016-02-08 13:45:40 +01:00
parent 28d0d87098
commit 8eb1ad543a
2 changed files with 14 additions and 8 deletions
+11 -8
View File
@@ -7,8 +7,8 @@ HotTestWidget::HotTestWidget(QWidget *parent) :
hotkey_1(new QHotkey(this)), hotkey_1(new QHotkey(this)),
hotkey_2(new QHotkey(this)), hotkey_2(new QHotkey(this)),
hotkey_3(new QHotkey(this)), hotkey_3(new QHotkey(this)),
hotkey_4(new QHotkey(this)), hotkey_4(new QHotkey(NULL)),
hotkey_5(new QHotkey(this)), hotkey_5(new QHotkey(NULL)),
thread4(new QThread(this)), thread4(new QThread(this)),
thread5(new QThread(this)), thread5(new QThread(this)),
testHotkeys() testHotkeys()
@@ -100,6 +100,9 @@ HotTestWidget::~HotTestWidget()
this->thread5->quit(); this->thread5->quit();
this->thread5->wait(); this->thread5->wait();
delete this->hotkey_4;
delete this->hotkey_5;
delete ui; delete ui;
} }
@@ -198,19 +201,19 @@ void HotTestWidget::on_threadEnableCheckBox_clicked()
Q_ASSERT(!this->hotkey_4->isRegistered()); Q_ASSERT(!this->hotkey_4->isRegistered());
Q_ASSERT(!this->hotkey_5->isRegistered()); Q_ASSERT(!this->hotkey_5->isRegistered());
this->hotkey_4->setParent(NULL);
this->hotkey_4->moveToThread(this->thread4); this->hotkey_4->moveToThread(this->thread4);
this->hotkey_5->setParent(NULL);
this->hotkey_5->moveToThread(this->thread5); this->hotkey_5->moveToThread(this->thread5);
QApplication::processEvents(); QApplication::processEvents();
Q_ASSERT(this->hotkey_4->thread() == this->thread4); Q_ASSERT(this->hotkey_4->thread() == this->thread4);
Q_ASSERT(this->hotkey_5->thread() == this->thread5); Q_ASSERT(this->hotkey_5->thread() == this->thread5);
connect(this->thread4, &QThread::finished, connect(this->thread4, &QThread::finished, this, [this](){
this->hotkey_4, &QHotkey::deleteLater); this->hotkey_4->moveToThread(qApp->thread());
connect(this->thread5, &QThread::finished, });
this->hotkey_5, &QHotkey::deleteLater); connect(this->thread5, &QThread::finished, this, [this](){
this->hotkey_5->moveToThread(qApp->thread());
});
this->ui->tabWidget->setCurrentIndex(0); this->ui->tabWidget->setCurrentIndex(0);
} }
+3
View File
@@ -6,12 +6,15 @@
#include <QPair> #include <QPair>
#include <QLoggingCategory> #include <QLoggingCategory>
//! A class to define global, systemwide Hotkeys
class QHotkey : public QObject class QHotkey : public QObject
{ {
Q_OBJECT Q_OBJECT
friend class QHotkeyPrivate; friend class QHotkeyPrivate;
//! Specifies whether this hotkey is currently registered or not
Q_PROPERTY(bool registered READ isRegistered WRITE setRegistered NOTIFY registeredChanged) Q_PROPERTY(bool registered READ isRegistered WRITE setRegistered NOTIFY registeredChanged)
//! Holds the shortcut this hotkey will be triggered on
Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut RESET resetShortcut) Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut RESET resetShortcut)
public: public: