//dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QLineEdit>
#include <QGridLayout>
class Dialog : public QDialog
{
    Q_OBJECT
public:
    Dialog(QWidget *parent = 0);
    ~Dialog();
private:
    QPushButton *fileBtn;
    QLineEdit *fileLineEdit;
    QGridLayout *mainLayout;
private slots:
    void showFile();
};
#endif // DIALOG_H

//dialog.cpp
#include "dialog.h"
#include <QGridLayout>
#include <QFileDialog>
#include <QPushButton>
Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle(tr("Every Standard Dialog Instance"));
    fileBtn=new QPushButton;
    fileBtn->setText(tr("File Standard Dialog Instance"));
    fileLineEdit=new QLineEdit;
    mainLayout=new QGridLayout(this);
    mainLayout->addWidget(fileBtn,0,0);
    mainLayout->addWidget(fileLineEdit,0,1);
    connect(fileBtn,SIGNAL(clicked()),this,SLOT(showFile()));
}
void Dialog::showFile()
{
    QString s=QFileDialog::getOpenFileName(this,"open file dialog","/",tr("Program Files (*.cpp *.c *.h)"));
    fileLineEdit->setText(s);
}
Dialog::~Dialog()
{
}

效果图:

Qt 打开文件实例_getOpenFileName

Qt 打开文件实例_文件_02

Qt 打开文件实例_qt_03