Recently, there is such a requirement: click the button to open a dialog box to select an image and display it on the UI. The
getOpenFileName() function parameter fills in the file path, and returns the path of the selected file
#include<QFileDialog>
void on_pushButton_clicked()
{
QString curPath=QDir::currentPath();//获取当前路径
QString str=QFileDialog::getOpenFileName(this,"打开文件",curPath);
// QString str=QFileDialog::getOpenFileName(this,"打开文件",".");//"." 代表程序运行目录
// QString str=QFileDialog::getOpenFileName(this,"打开文件","/");//"/" 代表当前盘符的根目录
qDebug()<<str;//E:\project\Camerasensor\AT_VI_V5.6.0.12_Win64\GoldenTool\1.bmp
//show图片
ui->label_PicHK->setPixmap(QPixmap(str));
}