Post some pictures, code below,
Pro file:
QT +=core GUI
GreaterThan (QT_MAJOR_VERSION, 4) : QT +=widgets
TARGET=20200223
The TEMPLATE=app
DEFINES +=QT_DEPRECATED_WARNINGS
INCLUDEPATH +=E:/opencv - 3.2.0/newbuild/install/include \
E:/opencv - 3.2.0/newbuild/install/include/opencv \
E:/opencv - 3.2.0/newbuild/install/include/opencv2
LIBS +=E:/opencv - 3.2.0/newbuild/install/x86/mingw/lib/libopencv_core320. DLL. A \
E:/opencv - 3.2.0/newbuild/install/x86/mingw/lib/libopencv_highgui320. DLL. A \
E:/opencv - 3.2.0/newbuild/install/x86/mingw/lib/libopencv_imgproc320. DLL. A \
E:/opencv - 3.2.0/newbuild/install/x86/mingw/lib/libopencv_imgcodecs320. DLL. A \
E:/opencv - 3.2.0/newbuild/install/x86/mingw/lib/libopencv_highgui320. DLL. A \
E:/opencv - 3.2.0/newbuild/install/x86/mingw/lib/libopencv_videoio320. DLL. A
SOURCES +=\
The main. CPP \
Mainwindow. CPP
HEADERS +=\
Mainwindow. H
FORMS +=\
Mainwindow. UI
Mainwindow. H
# # ifndef MAINWINDOW_H
# define MAINWINDOW_H
# include & lt; QMainWindow>
The namespace Ui {
The class MainWindow.
}
The class MainWindow: public QMainWindow
{
Q_OBJECT
Public:
Explicit MainWindow (QWidget * parent=0);
~ MainWindow ();
Private slots:
Void on_pushButton_clicked ();
Private:
Ui: : MainWindow * Ui;
};
# endif//MAINWINDOW_H
The main
# include "mainwindow. H"
# include & lt; QApplication>
Int main (int arg c, char * argv [])
{
QApplication a (arg c, argv);
The MainWindow w;
Baron how ();
Return a.e xec ();
}
Mainwindow. CPP
# include "mainwindow. H"
# include "ui_mainwindow. H"
#include
#include
#include
#include
Using the namespace CV;
MainWindow: : MainWindow (QWidget * parent) :
QMainWindow (parent),
UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);
}
MainWindow: : ~ MainWindow ()
{
Delete the UI;
}
Void MainWindow: : on_pushButton_clicked ()
{
QString img_name=QFileDialog: : getOpenFileName (this, tr (" Open Image "), ". ", the tr (" Image Files (*. PNG *. JPG *. Jpeg *. BMP) "));
Mat src=https://bbs.csdn.net/topics/imread (img_name toLatin1 (). The data ());
CV: : cvtColor (SRC, SRC, CV_BGR2RGB);
QImage img=QImage ((const unsigned char *) (SRC) data), SRC, cols, SRC, rows, QImage: : Format_RGB888);
The UI - & gt; PushButton - & gt; SetPixmap (QPixmap: : fromImage (img));
}
CodePudding user response:
SetPixmap is a function of QLabelYou have to learn to check document
SetIcon function button
CodePudding user response:
Qt provides an introduction to the three pictures of class, to learn how to use the help documentation, to check you need class: QImage, QPixmap, QBitmap, QPicture.CodePudding user response:
The meaning of this sentence is QPushButton setPixmap members of the class does not function