This commit is contained in:
2026-05-21 08:07:04 +08:00
parent 9903da092d
commit e52e5701f9
24 changed files with 695 additions and 0 deletions
+11
View File
@@ -9,9 +9,13 @@
#include "src/AppController.h"
// 函数作用:Qt 管理端程序入口,负责初始化应用、注册 C++ 控制器并加载主 QML 界面。
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// 应用图标同时注册多种尺寸,方便 Windows、Android 和任务栏在不同缩放比例下
// 选择最合适的资源,避免高 DPI 屏幕上图标发虚。
QIcon appIcon(QStringLiteral(":/assets/favicon.ico"));
appIcon.addFile(QStringLiteral(":/assets/favicon-256x256.png"));
appIcon.addFile(QStringLiteral(":/assets/favicon-192x192.png"));
@@ -28,12 +32,18 @@ int main(int argc, char *argv[])
QQuickStyle::setStyle("Basic");
#if defined(Q_OS_ANDROID)
// Android 端使用系统原生文字渲染,中文字体边缘会比默认距离场渲染更清晰。
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
#endif
// AppController 是 C++ 后端的统一入口,负责网络请求、本地缓存、数据筛选和导出。
// 下方通过 contextProperty 暴露给 QML,界面中可直接使用 appController 调用这些能力。
AppController controller;
QQmlApplicationEngine engine;
// 部分打包环境不会自动把 Qt 安装目录中的 QML 模块加入搜索路径,
// 这里显式补充一次,避免发布版运行时找不到 QtQuick.Controls 等模块。
const QString qmlImportPath = QLibraryInfo::path(QLibraryInfo::QmlImportsPath);
if (!qmlImportPath.isEmpty()) {
engine.addImportPath(qmlImportPath);
@@ -47,6 +57,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("appController", &controller);
const QUrl url(QStringLiteral("qrc:/qml/Main.qml"));
// 如果主 QML 创建失败,说明资源路径或依赖模块异常,直接退出便于定位启动问题。
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,