-
Notifications
You must be signed in to change notification settings - Fork 11
/
mainwindow.cpp
58 lines (50 loc) · 1.34 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "test_thread.h"
#include <QDebug>
/*****************************************
*
* Test_Thread 多线程 - run start
* Test_Thread2 多线程 - moveToThread
*
****************************************/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
test_2 = new Test_Thread2(this);
my_thread = new QThread(this);
test_2->moveToThread(my_thread);
connect(my_thread, &QThread::finished, test_2, &Test_Thread2::deleteLater);
connect(test_2, &Test_Thread2::sigResultReady, this, &MainWindow::onTest);
test_concurent = new Test_Concurent();
test_concurent->hide();
}
MainWindow::~MainWindow()
{
delete ui;
if (test_concurent){
delete test_concurent;
test_concurent = Q_NULLPTR;
}
}
void MainWindow::onTest(const QString &s)
{
qDebug() << s << s << s;
}
void MainWindow::on_pushButton_clicked()
{
Test_Thread* ts_th = new Test_Thread(this);
connect(ts_th, &Test_Thread::sigResultReady, this, &MainWindow::onTest);
connect(ts_th, &Test_Thread::finished, ts_th, &Test_Thread::deleteLater);
ts_th->start();
}
void MainWindow::on_pushButton_2_clicked()
{
test_2->doWork("test2");
}
void MainWindow::on_pushButton_3_clicked()
{
test_concurent->show();
}