介绍了Qt5 中 moveToThread() 方式开启线程,
以画图为载体。同时测试了信号槽连接函数第5个参数的不同枚举情况。
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
#include <QImage>
class MyThread : public QThread
{
Q_OBJECT
public:
explicit MyThread(QObject *parent = nullptr);
signals:
void finishImage(const QImage image);
public slots:
void drawImage();
void myt2slot();
void myt3slot();
void myt4slot();
};
#endif // MYTHREAD_H
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include "mythread.h"
#include <QImage>
#include <QThread>
namespace Ui {
class MyWidget;
}
class MyWidget : public QWidget
{
Q_OBJECT
public:
explicit MyWidget(QWidget *parent = nullptr);
~MyWidget();
protected:
void paintEvent(QPaintEvent *event);
private slots:
void closeWidget();
void getImage(const QImage& temp);
private:
Ui::MyWidget *ui;
MyThread* myT;
MyThread* myT2;
MyThread* myT3;
MyThread* myT4;
QThread *thread;
QImage image;
};
#endif // MYWIDGET_H