建立一個無UI的widget類:

main.cpp:
#include "widget.h"
#include <QApplication>
#include<QLabel>
#include<QImage>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
QLabel *label=new QLabel(&w);
QImage image("C:/Users/dyg/Desktop/QT/img.jpg");
label->setPixmap(QPixmap::fromImage(image));
label->setGeometry(0,0,image.width(),image.height());
w.show();
return a.exec();
}