-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
98 lines (78 loc) · 2.1 KB
/
mainwindow.cpp
File metadata and controls
98 lines (78 loc) · 2.1 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug() << this->parent();
connect(&m_timer, SIGNAL(timeout()), this, SLOT(slotMainShowInfo()));
m_timer.setInterval(1000 * 1); //所有状态信息的轮询间隔时间
m_timer.start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotMainShowInfo()
{
qDebug() << "Hello world!" << XThread::count();
}
void MainWindow::on_pushButton_clicked()
{
auto func1 = [&]()
{
int times = 30;
while(times--)
{
qDebug() << QString("thread1") << times;
QThread::msleep(100);
}
};
auto func2 = [&](int &ret)
{
int times = 40;
while(times--)
{
qDebug() << QString("thread2") << times;
QThread::msleep(100);
}
ret = 999999;//线程返回结果
};
auto func3 = [&](QString &retStr)
{
int times = 50;
while(times--)
{
qDebug() << QString("thread3") << times;
QThread::msleep(100);
}
retStr = "nice"; //线程返回结果
};
//! example 1
XThread *thread1 = new XThread;
thread1->setCallback(func1);
thread1->start();
// XThread *thread1 = new XThread(func1);
// thread1->start();
//! example 2
XThread *thread2 = new XThread(func2);
connect(thread2,SIGNAL(signalFinishResult(int)),this,SLOT(slotDebug(int)));
thread2->start();
//! example 3
XThread *thread3 = new XThread(func3);
connect(thread3,SIGNAL(signalFinishResult(QString)),this,SLOT(slotDebug(QString)));
thread3->start();
}
void MainWindow::slotDebug(QString str)
{
QMessageBox::information(this,"tips",str);
qDebug() << str;
}
void MainWindow::slotDebug(int val)
{
qDebug() << val;
QMessageBox::information(this,"tips", QString::number(val) );
}