forked from czyt1988/czyBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidget.cpp
More file actions
117 lines (103 loc) · 2.72 KB
/
Widget.cpp
File metadata and controls
117 lines (103 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "Widget.h"
#include "ui_Widget.h"
TestThread::TestThread(QObject *par):QThread(par)
,m_abort(false)
{
}
TestThread::~TestThread()
{
m_abort = true;
}
void TestThread::run()
{
while(!m_abort)
{
if(1)
{
int a = 1;
unsigned int add = (unsigned int)&a;
emit signalData(a,add);
}
sleep(1);
m_abort = true;
}
}
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
m_thread = new TestThread(this);
connect(this,SIGNAL(signalData(int,unsigned int))
,SLOT(recDataQueuedConnection(int,unsigned int))
,Qt::QueuedConnection
);
connect(this,SIGNAL(signalData(int,unsigned int))
,SLOT(recDataDirectConnection(int,unsigned int))
,Qt::DirectConnection
);
connect(m_thread,SIGNAL(signalData(int,unsigned int))
,SLOT(recThreadData(int,unsigned int))
);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_test_clicked()
{
if(!m_thread->isRunning())
{
m_thread->start();
}
int a = 1;
unsigned int add = (unsigned int)&a;
ui->textBrowser->append("start emit local signal");
emit signalData(a,add);
ui->textBrowser->append("after emit local signal");
}
void Widget::recDataDirectConnection(const int &a, unsigned int aAddress)
{
if(a != 1)
{
ui->textBrowser->append("a != 1");
}
if(aAddress != (unsigned int)&a)
{
ui->textBrowser->append(QString("DirectConnection addr not same,rec a:%1,thread a:%2").arg((unsigned int)&a).arg(aAddress));
}
else
{
ui->textBrowser->append(QString("DirectConnection addr is same,rec a:%1,thread a:%2").arg((unsigned int)&a).arg(aAddress));
}
}
void Widget::recThreadData(const int &a, unsigned int aAddress)
{
if(a != 1)
{
ui->textBrowser->append("a != 1");
}
if(aAddress != (unsigned int)&a)
{
ui->textBrowser->append(QString("[Thread]addr not same,rec a:%1,thread a:%2").arg((unsigned int)&a).arg(aAddress));
}
else
{
ui->textBrowser->append(QString("[Thread]addr is same,rec a:%1,thread a:%2").arg((unsigned int)&a).arg(aAddress));
}
}
void Widget::recDataQueuedConnection(const int &a, unsigned int aAddress)
{
if(a != 1)
{
ui->textBrowser->append("a != 1");
}
if(aAddress != (unsigned int)&a)
{
ui->textBrowser->append(QString("QueuedConnection addr not same,rec a:%1,thread a:%2").arg((unsigned int)&a).arg(aAddress));
}
else
{
ui->textBrowser->append(QString("QueuedConnection addr is same,rec a:%1,thread a:%2").arg((unsigned int)&a).arg(aAddress));
}
}