修复文件长度没有初始化造成大小计算不对

This commit is contained in:
sonichy 2022-11-16 13:19:37 +08:00
parent 1d929fa67a
commit 5cd65b237b
4 changed files with 5 additions and 5 deletions

BIN
FileTrans

Binary file not shown.

View File

@ -111,7 +111,7 @@ void MainWindow::newConnect()
void MainWindow::readyRead()
{
QByteArray BA = tcpSocket->readAll();
//qDebug() << BA ;
QString IP_remote = tcpSocket->peerAddress().toString().replace("::ffff:","") + ":" + QString::number(tcpSocket->peerPort());
if (state == 0) {
QString s = BA;
QJsonParseError JPE;
@ -123,18 +123,18 @@ void MainWindow::readyRead()
type = JO.value("type").toString();
if (type == "text") {
QString message = JO.value("message").toString();
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] " + "接收" + message);
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "]" + message);
} else if(type == "file") {
fileName = JO.value("fileName").toString();
lastModified = JO.value("lastModified").toDouble()/1000;
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] " + "接收" + fileName);
ui->textBrowser->append("[" + QDateTime::currentDateTime().toString("HH:mm:ss") + "] [" + IP_remote + "]" + fileName);
QString filepath = ui->lineEdit_root_dir->text() + "/" + fileName;
file.setFileName(filepath);
file.open(QIODevice::WriteOnly);
}
}
}
} else {
} else if (state == 1) {
file.write(BA);
length += BA.length();
ui->statusBar->showMessage("接收:" + BS(length));

View File

@ -40,7 +40,7 @@ private:
QTcpSocket *tcpSocket;
int state;
QFile file;
qint64 length, port_local;
qint64 length=0, port_local;
QString BS(long b);
void upload(QString filepath);
double lastModified = 0;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 45 KiB