介绍使用 Qt run() 开启线程的基本函数,信号,槽,已经过程。
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
class MyThread : public QThread
{
Q_OBJECT
public:
explicit MyThread(QObject *parent = nullptr);
//start函数间接调用了run()
void run();
signals:
void isDoneSignal();
public slots:
};
#endif // MYTHREAD_H
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include <QTimer>
#include "mythread.h"
namespace Ui {
class MyWidget;
}
class MyWidget : public QWidget
{
Q_OBJECT
public:
explicit MyWidget(QWidget *parent = nullptr);
~MyWidget();
public slots:
void executeslot();
private slots:
void on_pushButton_clicked();
void dealThreadSlot();
void mythreadStartedSlot();
void mythreadFinishedSlot();
void stopThread(