运行结果图:
MyThread.h:
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QObject>
#include<QThread>
#include<QImage>
#include<QPainter>
#include<QPoint>
#include<QBrush>
#include<QPen>
class MyThread : public QObject
{
Q_OBJECT
public:
explicit MyThread(QObject *parent = nullptr);
//线程处理函数
void drawImage();
signals:
//发出信号
void updateImage(QImage img);
};
#endif // MYTHREAD_H
MyThread.cpp:
#include "mythread.h"
MyThread::MyThread(QObject *parent) : QObject(parent)
{
}
void MyThread::drawImage()
{
//定义QImage绘图设备
QImage image(500,500,QImage::Format_AR