main.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <QGuiApplication>
  2. #include <QQmlApplicationEngine>
  3. #include <QQmlContext>
  4. #include <qqml.h>
  5. #include "user/config.h"
  6. #include "user/lock.h"
  7. #include "user/rfid.h"
  8. #include "user/pro.h"
  9. #include "user/httpclient.h"
  10. #include "user/finger.h"
  11. #include "user/logoutput.h"
  12. #include "user/timeout.h"
  13. #include <QLoggingCategory>
  14. #include "Interactive/InteractiveCore.h"
  15. #include "Interactive/InteractiveWork.h"
  16. #include "Interactive/InteractiveData.h"
  17. #include "Interactive/InteractiveFace.h"
  18. #include "Interactive/InteractiveHand.h"
  19. #include <windows.h>
  20. config *pconfig = new config();
  21. int main(int argc, char *argv[])
  22. {
  23. QGuiApplication app(argc, argv);
  24. if(false == pconfig->configRead())
  25. {
  26. pconfig->configWrite();
  27. }
  28. // qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
  29. // 日志模块初始化(将QDebug重定向到文件)
  30. if(pconfig->logfileStat == true)
  31. {
  32. LogOutput::getInstance()->install();
  33. }
  34. // 注册 Worker 类到 QML
  35. qmlRegisterType<lock>("com.lock", 1, 0, "Lock");
  36. qmlRegisterType<rfid>("com.rfid", 1, 0, "Rfid");
  37. qmlRegisterType<pro>("com.pro", 1, 0, "Pro");
  38. qmlRegisterType<httpClient>("com.httpclient", 1, 0, "Httpclient");
  39. qmlRegisterType<finger>("com.finger", 1, 0, "Finger");
  40. qmlRegisterType<timeout>("com.timeout", 1, 0, "Timeout");
  41. qmlRegisterType<InteractiveTask>("com.InteractiveTask", 1, 0, "InteractiveTask"); // 将任务操作类注册到qml
  42. // qmlRegisterType<InteractiveCore>("com.InteractiveCore", 1, 0, "InteractiveCore");
  43. // qmlRegisterType<InteractiveData>("com.InteractiveData", 1, 0, "InteractiveData");
  44. // qmlRegisterType<InteractiveFace>("com.InteractiveFace", 1, 0, "InteractiveFace");
  45. // 创建全局单例 数据缓存
  46. InteractiveCore *pSingletonCore = SINGLETON_CREATE(InteractiveCore)(); // 核心模块
  47. InteractiveWork *pSingletonWork = SINGLETON_CREATE(InteractiveWork)(); // 工作模块
  48. InteractiveData *pSingletonData = SINGLETON_CREATE(InteractiveData)(); // 数据模块
  49. InteractiveFace *pSingletonFace = SINGLETON_CREATE(InteractiveFace)(); // 人脸模块
  50. InteractiveHand *pSingletonHand = SINGLETON_CREATE(InteractiveHand)(); // 指纹模块
  51. QQmlApplicationEngine engine;
  52. // 注册单例类到qml
  53. engine.rootContext()->setContextProperty("interactiveCore", pSingletonCore);
  54. engine.rootContext()->setContextProperty("interactiveData", pSingletonData);
  55. engine.rootContext()->setContextProperty("interactiveFace", pSingletonFace);
  56. engine.rootContext()->setContextProperty("interactiveHand", pSingletonHand);
  57. // 注册图像地址(人脸/指纹)到qml
  58. engine.addImageProvider(INTERACTIVE_FACE_IMAGE_URL, pSingletonFace);
  59. engine.addImageProvider(INTERACTIVE_HAND_IMAGE_URL, pSingletonHand);
  60. // 注册模型到qml
  61. engine.rootContext()->setContextProperty("materialreplace_modelMaterialType", &pSingletonData->m_modelMaterialType);
  62. engine.rootContext()->setContextProperty("materialreplace_modelMaterialInfo", &pSingletonData->m_modelMaterialInfo);
  63. engine.rootContext()->setContextProperty("materialreplace_modelMaterialManualReplace", &pSingletonData->m_modelMaterialManualReplace);
  64. engine.rootContext()->setContextProperty("materialexception_modelMaterialException", &pSingletonData->m_modelMaterialException);
  65. engine.rootContext()->setContextProperty("appDir",
  66. QString("file:///") +
  67. qApp->applicationDirPath());
  68. engine.rootContext()->setContextProperty("pConfig", pconfig);
  69. const QUrl url(QStringLiteral("qrc:/Cabinet/main.qml"));
  70. QObject::connect(
  71. &engine,
  72. &QQmlApplicationEngine::objectCreated,
  73. &app,
  74. [url](QObject *obj, const QUrl &objUrl) {
  75. if (!obj && url == objUrl)
  76. QCoreApplication::exit(-1);
  77. },
  78. Qt::QueuedConnection);
  79. engine.load(url);
  80. return app.exec();
  81. }