chore:qdebug输出显示下载进度

This commit is contained in:
2025-06-11 11:18:44 +08:00
parent 616453ed7d
commit d5af9c2cf1
2 changed files with 21 additions and 7 deletions

View File

@@ -35,16 +35,31 @@ void DownloadManager::startDownload(const QString &appName)
void DownloadManager::onProcessReadyRead() void DownloadManager::onProcessReadyRead()
{ {
QByteArray output = m_process->readAllStandardOutput(); static QString buffer; // 缓存未处理的输出
QString outputStr = QString::fromUtf8(output); buffer += QString::fromUtf8(m_process->readAllStandardOutput());
QRegularExpressionMatch match = m_progressRegex.match(outputStr); const QStringList lines = buffer.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
if (match.hasMatch()) {
int progress = match.captured(1).toInt(); for (const QString &line : lines) {
emit downloadProgress(progress); QRegularExpressionMatch match = m_progressRegex.match(line);
if (match.hasMatch()) {
int progress = match.captured(1).toInt();
qDebug() << "匹配进度:" << progress << "% => " << line;
emit downloadProgress(progress);
} else {
// qDebug() << "未匹配行:" << line;
}
}
// 如果最后不是完整的一行,保留最后一部分
if (!buffer.endsWith('\n') && !buffer.endsWith('\r')) {
buffer = lines.last();
} else {
buffer.clear();
} }
} }
void DownloadManager::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void DownloadManager::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{ {
bool success = (exitStatus == QProcess::NormalExit && exitCode == 0); bool success = (exitStatus == QProcess::NormalExit && exitCode == 0);

View File

@@ -4,7 +4,6 @@
#include <QObject> #include <QObject>
#include <QProcess> #include <QProcess>
#include <QRegularExpression> #include <QRegularExpression>
class DownloadManager : public QObject class DownloadManager : public QObject
{ {
Q_OBJECT Q_OBJECT