-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_file_dialog.cpp
84 lines (64 loc) · 1.88 KB
/
send_file_dialog.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "send_file_dialog.h"
#include "ui_send_file_dialog.h"
#include <QFileDialog>
SendFileDialog::SendFileDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SendFileDialog)
{
ui->setupUi(this);
this->selectedFile = "";
this->selectedFileNameOnly = "";
this->ui->label->setText("");
this->ui->progressBar->setRange(0, 100);
this->ui->progressBar->reset();
this->file = QFileInfo();
}
SendFileDialog::~SendFileDialog()
{
delete ui;
}
void SendFileDialog::SetProgress(int progress)
{
this->ui->progressBar->setValue(progress);
qApp->processEvents();
}
void SendFileDialog::on_btnSelect()
{
//定义文件对话框类
QFileDialog *fileDialog = new QFileDialog(this);
//定义文件对话框标题
fileDialog->setWindowTitle(QStringLiteral("请选择文件..."));
//设置默认文件路径
fileDialog->setDirectory("~/");
//设置文件过滤器
fileDialog->setNameFilter(tr("File(*.*)"));
//设置可以选择多个文件,默认为只能选择一个文件QFileDialog::ExistingFiles
fileDialog->setFileMode(QFileDialog::ExistingFiles);
//设置视图模式
fileDialog->setViewMode(QFileDialog::Detail);
//所有选择的文件的路径
QStringList fileNames;
if (fileDialog->exec())
{
fileNames = fileDialog->selectedFiles();
}
if (fileNames.length() == 0)
{
return;
}
this->selectedFile = fileNames.at(0);
this->file.setFile(selectedFile);
this->selectedFileNameOnly = this->file.fileName();
double megaBytes = this->file.size() / 1e6;
this->ui->label->setText(this->selectedFileNameOnly + " " + QString::number(megaBytes, 'g', 2) + "MB");
this->ui->progressBar->reset();
// this->file = QFileInfo();
}
void SendFileDialog::on_btnSend()
{
if (this->selectedFile == "")
{
return;
}
emit this->sendFile();
}