MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "Mythread.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void SlotNum(QString num);
private:
Ui::MainWindow *ui;
Mythread *my_thread_;
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
my_thread_ = new Mythread(this);
connect(my_thread_, &Mythread::SigNum, this, &MainWindow::SlotNum);
connect(ui->pushButton_open, &QPushButton::clicked, this, [=]
{
my_thread_->stopwork(false);//开始
my_thread