【QT】打开文件对话框,选择路径下文件

时间:2021-09-15 12:22:09

0、头文件中加入

public:
    QString fileName;
public slots:
    void showImage();

1、添加两个头文件

#include<qfiledialog.h>
#include<qstring.h>

2、QFileDialog::getOpenFileName

槽函数中加入:

    QString lastPath="D:\Englishpath\QTprojects\DATA\videoData";
    QString fileName = QFileDialog::getOpenFileName(this, tr("打开文件"), lastPath);

 

connect:

    connect(ui->m_openFile,SIGNAL(clicked(bool)),this,SLOT(showImage()));