#include<QFileDialog>
#include<QFile>
QString filter ="所有(*);;"
“源码(*.cpp *.h);;”
"文本(*.txt)";
//1弹出选择对话框
QString pathname = QFileDialog::getOpenFileName(this,"选择文件",filter);
if(pathname.isNull())
return;
//2 将文件的名称显示到输入栏中
ui->lineEdit->setText(pathname);
//3将文件的内容显示到文本框中
QFile file(pathname);
file.open(QIODevice::ReadOnly);
ui->plainTextEdit->clear();
ui->plainTextEdit->appendPlainText(file.readAll());