-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetfile.cpp
More file actions
41 lines (40 loc) · 1.04 KB
/
getfile.cpp
File metadata and controls
41 lines (40 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "getfile.h"
#include <QFileInfo>
#include <QMessageBox>
getFile::getFile(QWidget *parent)
: QWidget{parent}
{
fl=new FileLine(this);
pushbutton=new QPushButton("打开文件",this);
layout=new QHBoxLayout(this);
layout->addWidget(pushbutton);
layout->addWidget(fl);
connect(pushbutton,&QPushButton::clicked,this,&getFile::pushButton_clicked);
connect(fl,&QLineEdit::returnPressed,this,&getFile::editFinish);
connect(fl,&FileLine::changed,this,&getFile::fileChanged);
}
getFile::~getFile()
{
delete layout;
}
void getFile::pushButton_clicked()
{
QString path=QFileDialog::getOpenFileName(this,tr("打开文件"),"");
fl->setText(path);
fl->Filepath=path;
emit fileChanged();
}
void getFile::editFinish()
{
QString name=fl->text();
QFileInfo inputFile(name);
if(inputFile.isFile())
{
fl->Filepath=name;
emit fileChanged();
}
else
{
QMessageBox::warning(this,"Error","Please input a valid file.");
}
}