added thread test -> fails on windows

This commit is contained in:
Skycoder42
2016-02-06 17:34:58 +01:00
parent cbdcfeed95
commit 2f31a06430
3 changed files with 99 additions and 2 deletions
+31 -2
View File
@@ -7,11 +7,15 @@ HotTestWidget::HotTestWidget(QWidget *parent) :
hotkey_1(new QHotkey(this)),
hotkey_2(new QHotkey(this)),
hotkey_3(new QHotkey(this)),
hotkey_4(new QHotkey(this)),
hotkey_5(new QHotkey(this)),
hotkey_4(new QHotkey(NULL)),
hotkey_5(new QHotkey(NULL)),
thread4(new QThread(this)),
thread5(new QThread(this)),
testHotkeys()
{
ui->setupUi(this);
this->thread4->start();
this->thread5->start();
//1
connect(this->ui->hotkeyCheckbox_1, &QCheckBox::toggled,
@@ -91,6 +95,11 @@ HotTestWidget::HotTestWidget(QWidget *parent) :
HotTestWidget::~HotTestWidget()
{
this->thread4->quit();
this->thread4->wait();
this->thread5->quit();
this->thread5->wait();
delete ui;
}
@@ -174,3 +183,23 @@ void HotTestWidget::on_groupBox_toggled(bool checked)
for(QHotkey *hotkey : this->testHotkeys)
hotkey->setRegistered(checked);
}
void HotTestWidget::on_threadEnableCheckBox_clicked(bool checked)
{
this->ui->hotkeyCheckbox_1->setChecked(false);
this->ui->hotkeyCheckbox_2->setChecked(false);
this->ui->hotkeyCheckbox_3->setChecked(false);
this->ui->hotkeyCheckbox_4->setChecked(false);
this->ui->hotkeyCheckbox_5->setChecked(false);
Q_ASSERT(!this->hotkey_4->isRegistered());
Q_ASSERT(!this->hotkey_5->isRegistered());
if(checked) {
this->hotkey_4->moveToThread(this->thread4);
this->hotkey_5->moveToThread(this->thread5);
} else {
this->hotkey_4->moveToThread(this->thread());
this->hotkey_5->moveToThread(this->thread());
}
}
+6
View File
@@ -3,6 +3,7 @@
#include <QWidget>
#include <QHotkey>
#include <QThread>
namespace Ui {
class HotTestWidget;
@@ -37,6 +38,8 @@ private slots:
void on_groupBox_toggled(bool checked);
void on_threadEnableCheckBox_clicked(bool checked);
private:
Ui::HotTestWidget *ui;
@@ -46,6 +49,9 @@ private:
QHotkey *hotkey_4;
QHotkey *hotkey_5;
QThread *thread4;
QThread *thread5;
QList<QHotkey*> testHotkeys;
};
+62
View File
@@ -916,6 +916,68 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="threadTab">
<attribute name="title">
<string>Threading</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>12</number>
</property>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use this test to determine whether shortcuts on multiple threads are supported or not. Internally, the backend of the QHotkey class is &lt;span style=&quot; font-weight:600;&quot;&gt;threadsafe&lt;/span&gt;, and thus QHotkey is reentrant and can be used on any thread. However, some operating systems might not support creating hotkeys from different threads. &lt;/p&gt;&lt;p&gt;To enable threading, check the box below and return to the playground. &lt;span style=&quot; font-style:italic;&quot;&gt;Hotkey 4 and 5&lt;/span&gt; will now each run on their own thread. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="threadEnableCheckBox">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Enable Threaded Hotkeys</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Results so far:&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; text-decoration: underline;&quot;&gt;Windows:&lt;/span&gt; Registering on multiple threads is possible, but: The thread that registered must unregister too and events will be send to the thread registered from, not the main thread&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>