mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
added thread test -> fails on windows
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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><html><head/><body><p>Use this test to determine whether shortcuts on multiple threads are supported or not. Internally, the backend of the QHotkey class is <span style=" font-weight:600;">threadsafe</span>, and thus QHotkey is reentrant and can be used on any thread. However, some operating systems might not support creating hotkeys from different threads. </p><p>To enable threading, check the box below and return to the playground. <span style=" font-style:italic;">Hotkey 4 and 5</span> will now each run on their own thread. </p></body></html></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><html><head/><body><p><span style=" font-weight:600;">Results so far:</span></p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Windows:</span> 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</li></ul></body></html></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>
|
||||
|
||||
Reference in New Issue
Block a user