#include #include #include #include #include #include #include #include #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")); appIcon.addFile(QStringLiteral(":/assets/favicon-128x128.png")); appIcon.addFile(QStringLiteral(":/assets/favicon-64x64.png")); appIcon.addFile(QStringLiteral(":/assets/favicon-48x48.png")); appIcon.addFile(QStringLiteral(":/assets/favicon-32x32.png")); appIcon.addFile(QStringLiteral(":/assets/favicon-16x16.png")); app.setWindowIcon(appIcon); QCoreApplication::setApplicationName("人脸识别考勤系统"); QCoreApplication::setApplicationVersion("3.0.0"); QCoreApplication::setOrganizationName("STM32 Face Recognition"); 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); } #if defined(REWRITE_QT_INSTALL_QML) const QString qtInstallQmlPath = QStringLiteral(REWRITE_QT_INSTALL_QML); if (QDir(qtInstallQmlPath).exists()) { engine.addImportPath(qtInstallQmlPath); } #endif engine.rootContext()->setContextProperty("appController", &controller); const QUrl url(QStringLiteral("qrc:/qml/Main.qml")); // 如果主 QML 创建失败,说明资源路径或依赖模块异常,直接退出便于定位启动问题。 QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) { QCoreApplication::exit(-1); } }, Qt::QueuedConnection); engine.load(url); return app.exec(); }