diff --git a/FileTrans b/FileTrans index e9ce171..9871d19 100644 Binary files a/FileTrans and b/FileTrans differ diff --git a/mainwindow.cpp b/mainwindow.cpp index 0244e05..ebba641 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -142,6 +142,7 @@ void MainWindow::readyRead() ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "] open " + surl); } else if (type == "file") { fileName = JO.value("fileName").toString(); + fileLength = JO.value("fileLength").toDouble(); lastModified = JO.value("lastModified").toDouble()/1000; ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "]:" + fileName); QString filepath = ui->lineEdit_root_dir->text() + "/" + fileName; @@ -151,9 +152,12 @@ void MainWindow::readyRead() } } } else if (state == 1) { - file.write(BA); + file.write(BA); length += BA.length(); - ui->statusBar->showMessage("接收:" + BS(length)); + if (fileLength != 0) { + int p = length * 100 / fileLength; + ui->statusBar->showMessage("接收:" + BS(length) + "/" + BS(fileLength) + "=" + p + "%"); + } } } @@ -378,4 +382,4 @@ void MainWindow::dropEvent(QDropEvent *e) //释放对方时,执行的操作 qDebug() << filepath; upload(filepath); } -} \ No newline at end of file +} diff --git a/mainwindow.h b/mainwindow.h index 8d7d654..b4367bc 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -45,7 +45,7 @@ private: QTcpSocket *tcpSocket; int state; QFile file; - qint64 length=0, port_local; + qint64 length=0, fileLength, port_local; QString BS(long b); void upload(QString filepath); void upload(QPixmap pixmap, QHostAddress hostAddress, quint64 port); @@ -63,4 +63,4 @@ private slots: }; -#endif // MAINWINDOW_H \ No newline at end of file +#endif // MAINWINDOW_H