修复进度除数为0崩溃

This commit is contained in:
sonichy 2025-07-28 17:01:40 +08:00
parent ae2d00bf59
commit d90aabec31
3 changed files with 9 additions and 5 deletions

BIN
FileTrans

Binary file not shown.

View File

@ -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;
@ -153,7 +154,10 @@ void MainWindow::readyRead()
} else if (state == 1) {
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 + "%");
}
}
}

View File

@ -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);