修复进度除数为0崩溃
This commit is contained in:
parent
ae2d00bf59
commit
d90aabec31
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
Loading…
Reference in New Issue