main.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include <string>
  2. #include "Ego.h"
  3. #include "EgoInterface.h"
  4. #include "ImageProvider.h"
  5. #include "appmodel.h"
  6. #include <QGuiApplication>
  7. #include <QQmlApplicationEngine>
  8. #include <QtCore/QDir>
  9. #include"readthread.h"
  10. #include <QtQml/QQmlEngine>
  11. #include <QtQuick>
  12. #include <QtWidgets/QApplication>
  13. #include <dbghelp.h>
  14. #include <tchar.h>
  15. #pragma comment(lib, "dbghelp.lib")
  16. #define USER_DATA_BUFFER_SIZE (4096)
  17. long __stdcall exceptionHander(_EXCEPTION_POINTERS* excp);
  18. int main(int argc, char *argv[]) {
  19. //SetUnhandledExceptionFilter(exceptionHander);
  20. // qputenv("QSG_RHI_BACKEND", "opengl");
  21. QApplication app(argc, argv);
  22. // QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
  23. QQuickView viewer;
  24. std::array<IRender *, RenderPosition::ALL> ar;
  25. IEgoNotify *_notify;
  26. IEgoControl *_control;
  27. for (int i = 0; i < RenderPosition::ALL; i++) {
  28. ar[i] = new ShowImage(nullptr,static_cast< RenderPosition>(i));
  29. }
  30. _notify = new CEgoNotify();
  31. _control = GetEgoController(_notify);
  32. _control->Start(ar);
  33. QQmlEngine *engine = viewer.engine();
  34. // Front Cam
  35. ShowImage *FrontImage = static_cast<ShowImage *>(ar[0]);
  36. //FrontImage->campos = RenderPosition::FRONT;
  37. engine->rootContext()->setContextProperty("FrontImage", FrontImage);
  38. engine->addImageProvider(QLatin1String("FrontImage"),
  39. FrontImage->m_pImgProvider);
  40. // Back Cam
  41. ShowImage *BackImage = static_cast<ShowImage *>(ar[1]);
  42. // BackImage->campos = RenderPosition::BACK;
  43. engine->rootContext()->setContextProperty("BackImage", BackImage);
  44. engine->addImageProvider(QLatin1String("BackImage"),
  45. BackImage->m_pImgProvider);
  46. // Left Cam
  47. ShowImage *LeftImage = static_cast<ShowImage *>(ar[2]);
  48. //LeftImage->campos = RenderPosition::LEFT;
  49. engine->rootContext()->setContextProperty("LeftImage", LeftImage);
  50. engine->addImageProvider(QLatin1String("LeftImage"),
  51. LeftImage->m_pImgProvider);
  52. // Right Cam
  53. ShowImage *RightImage = static_cast<ShowImage *>(ar[3]);
  54. //RightImage->campos = RenderPosition::RIGHT;
  55. engine->rootContext()->setContextProperty("RightImage", RightImage);
  56. engine->addImageProvider(QLatin1String("RightImage"),
  57. RightImage->m_pImgProvider);
  58. //Panel Cam
  59. ShowImage* LeftAnchor = static_cast<ShowImage*>(ar[4]);
  60. //LeftAnchor->campos = RenderPosition::LANCHOR;
  61. engine->rootContext()->setContextProperty("LeftAnchor", LeftAnchor);
  62. engine->addImageProvider(QLatin1String("LeftAnchor"),
  63. LeftAnchor->m_pImgProvider);
  64. /* ShowImage* RightAnchor = static_cast<ShowImage*>(ar[5]);
  65. //RightAnchor->campos = RenderPosition::RANCHOR;
  66. engine->rootContext()->setContextProperty("RightAnchor", RightAnchor);
  67. engine->addImageProvider(QLatin1String("RightAnchor"),
  68. RightAnchor->m_pImgProvider);*/
  69. QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
  70. #ifdef Q_OS_WIN
  71. QString extraImportPath(QStringLiteral("%1/../../../../%2"));
  72. #else
  73. QString extraImportPath(QStringLiteral("%1/../../../%2"));
  74. #endif
  75. viewer.engine()->addImportPath(extraImportPath.arg(
  76. QGuiApplication::applicationDirPath(), QString::fromLatin1("qml")));
  77. QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer,
  78. &QWindow::close);
  79. //设置视图标题
  80. viewer.setTitle(QStringLiteral("Hyper vision remote control System"));
  81. //设置视图来源
  82. viewer.setSource(QUrl("qrc:///main.qml"));
  83. //设置视图自动调整大小
  84. viewer.setResizeMode(QQuickView::SizeRootObjectToView);
  85. //创建了一个名为item的指针,指向QML视图中的根对象
  86. QObject *item = viewer.rootObject();
  87. //在item(QML视图的根对象)中查找名为"tst"的子对象
  88. auto object = item->findChild<QObject*>("tst");
  89. if (object==nullptr)
  90. {
  91. qDebug() << "ColorSetting failed\n";
  92. }
  93. AppModel* appModel = new AppModel(_notify, _control,object);
  94. viewer.rootContext()->setContextProperty("appModel", appModel);
  95. ReadThread* readThread = new ReadThread();
  96. viewer.rootContext()->setContextProperty("readThread", readThread);
  97. //在QML中触发最大化窗口的信号时,显示窗口
  98. QObject::connect(item, SIGNAL(qmlSignalMaxWindow()), &viewer, SLOT(show()));
  99. //在QML中触发退出应用程序的信号时,执行相应的关闭操作
  100. QObject::connect(item, SIGNAL(qmlSignalQuit()), appModel, SLOT(OnClose()));
  101. viewer.setFlags(Qt::FramelessWindowHint | Qt::Window);
  102. viewer.showMinimized();
  103. return app.exec();
  104. }
  105. /*
  106. long exceptionHander(_EXCEPTION_POINTERS* excp)
  107. {
  108. TCHAR m_szDumpPath[_MAX_PATH];
  109. TCHAR m_szAppPath[_MAX_PATH];
  110. TCHAR m_szAppBaseName[_MAX_PATH];
  111. time_t m_lTime;
  112. time(&m_lTime);
  113. LONG retval = EXCEPTION_CONTINUE_SEARCH;
  114. HMODULE hDll = NULL;
  115. //TCHAR szDbgHelpPath[_MAX_PATH];
  116. if (GetModuleFileName(NULL, m_szAppPath, _MAX_PATH))
  117. {
  118. TCHAR* pSlash = _tcsrchr(m_szAppPath, '\\');
  119. if (pSlash)
  120. {
  121. _tcsncpy_s(m_szAppBaseName, _MAX_PATH, pSlash + 1, _MAX_PATH);
  122. *(pSlash + 1) = 0;
  123. // SetDumpFileName
  124. wsprintf(m_szDumpPath, _T("%s%s.%ld.dmp"), m_szAppPath, m_szAppBaseName, m_lTime);
  125. }
  126. }
  127. TCHAR szScratch[USER_DATA_BUFFER_SIZE];
  128. // ask the user if they want to save a dump file
  129. wsprintf(szScratch, _T("There was an unexpected error:\n\n%s\nWould you like to save a diagnostic file?\n\nFilename: %s"), "", m_szDumpPath);
  130. if (::MessageBox(NULL, szScratch, NULL, MB_YESNO) != IDYES)
  131. return EXCEPTION_EXECUTE_HANDLER;
  132. //创建转储文件
  133. HANDLE hFile = CreateFile(m_szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
  134. CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  135. LPCTSTR szResult = NULL;
  136. if (hFile != INVALID_HANDLE_VALUE)
  137. {
  138. MINIDUMP_EXCEPTION_INFORMATION exptInfo;
  139. exptInfo.ThreadId = ::GetCurrentThreadId();
  140. exptInfo.ExceptionPointers = excp;
  141. exptInfo.ClientPointers = NULL;
  142. //将dump信息写入到文件中
  143. BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(),
  144. GetCurrentProcessId(),
  145. hFile, MiniDumpNormal,
  146. &exptInfo, NULL, NULL);
  147. if (bOK)
  148. {
  149. szResult = NULL;
  150. retval = EXCEPTION_EXECUTE_HANDLER;
  151. }
  152. else
  153. {
  154. wsprintf(szScratch, _T("Failed to save dump file to '%s' (error %d)"), m_szDumpPath, GetLastError());
  155. szResult = szScratch;
  156. }
  157. ::CloseHandle(hFile);
  158. }
  159. else
  160. {
  161. wsprintf(szScratch, _T("Failed to create dump file '%s' (error %d)"), m_szDumpPath, GetLastError());
  162. szResult = szScratch;
  163. }
  164. if (szResult)
  165. ::MessageBox(NULL, szResult, NULL, MB_OK);
  166. TerminateProcess(GetCurrentProcess(), 0);
  167. return EXCEPTION_CONTINUE_SEARCH;
  168. }
  169. */