fix: Can not get app version

This commit is contained in:
2025-11-10 20:28:14 +08:00
parent 91040dbef7
commit 7bc97e0c3a

View File

@@ -10,6 +10,7 @@
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QCoreApplication>
DataCollectorAndUploader::DataCollectorAndUploader(QObject *parent) : QObject(parent) DataCollectorAndUploader::DataCollectorAndUploader(QObject *parent) : QObject(parent)
{ {
@@ -27,11 +28,17 @@ void DataCollectorAndUploader::collectData()
QString architecture; QString architecture;
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat); QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
QString version = config.value("build/version").toString(); QString version = QString(APP_VERSION); // 使用编译时定义的版本号
QString uuid = config.value("info/uuid").toString(); QString uuid = config.value("info/uuid").toString();
// Read /etc/os-release file // 根据环境变量选择 os-release 文件路径
QFile osReleaseFile("/etc/os-release"); QString osReleasePath = "/etc/os-release";
if (qEnvironmentVariableIsSet("IS_ACE_ENV") && qgetenv("IS_ACE_ENV") == "1") {
osReleasePath = "/host/etc/os-release";
}
// Read os-release file
QFile osReleaseFile(osReleasePath);
if (osReleaseFile.open(QIODevice::ReadOnly | QIODevice::Text)) { if (osReleaseFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&osReleaseFile); QTextStream in(&osReleaseFile);
while (!in.atEnd()) { while (!in.atEnd()) {
@@ -44,7 +51,7 @@ void DataCollectorAndUploader::collectData()
} }
osReleaseFile.close(); osReleaseFile.close();
} else { } else {
qWarning() << "Could not open /etc/os-release file"; qWarning() << "Could not open os-release file:" << osReleasePath;
} }
// Execute uname -m to get the architecture // Execute uname -m to get the architecture
@@ -83,4 +90,4 @@ void DataCollectorAndUploader::collectData()
} }
reply->deleteLater(); reply->deleteLater();
}); });
} }