main.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #include <string>
  2. #include <stdint.h>
  3. #include <memory>
  4. #include "../common/comm.h"
  5. #include "Ego.h"
  6. #include "ImageProvider.h"
  7. #include "appmodel.h"
  8. #include <QGuiApplication>
  9. #include <QQmlApplicationEngine>
  10. #include <QtCore/QDir>
  11. #include <QtQml/QQmlEngine>
  12. #include <QtQuick>
  13. #include <QtWidgets/QApplication>
  14. #include <dbghelp.h>
  15. #include <tchar.h>
  16. #pragma comment(lib, "dbghelp.lib")
  17. #define USER_DATA_BUFFER_SIZE (4096)
  18. long __stdcall exceptionHander(_EXCEPTION_POINTERS* excp);
  19. int main(int argc, char *argv[]) {
  20. //SetUnhandledExceptionFilter(exceptionHander);
  21. // qputenv("QSG_RHI_BACKEND", "opengl");
  22. QApplication app(argc, argv);
  23. // QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
  24. QQuickView viewer;
  25. std::array<IRender *, RenderPosition::ALL> ar;
  26. IMonitroNotify *_notify;
  27. IRemoteCtrl *_control;
  28. for (int i = 0; i < RenderPosition::ALL; i++) {
  29. ar[i] = new ShowImage(nullptr,static_cast< RenderPosition>(i));
  30. }
  31. _notify = new CEgoNotify();
  32. _control = GetRemoteController(_notify);
  33. _control->Start(EgoType::Monitor, ar);
  34. QQmlEngine *engine = viewer.engine();
  35. // Front Cam
  36. ShowImage *FrontImage = static_cast<ShowImage *>(ar[0]);
  37. //FrontImage->campos = RenderPosition::FRONT;
  38. engine->rootContext()->setContextProperty("FrontImage", FrontImage);
  39. engine->addImageProvider(QLatin1String("FrontImage"),
  40. FrontImage->m_pImgProvider);
  41. // Back Cam
  42. ShowImage *BackImage = static_cast<ShowImage *>(ar[1]);
  43. // BackImage->campos = RenderPosition::BACK;
  44. engine->rootContext()->setContextProperty("BackImage", BackImage);
  45. engine->addImageProvider(QLatin1String("BackImage"),
  46. BackImage->m_pImgProvider);
  47. // Left Cam
  48. ShowImage *LeftImage = static_cast<ShowImage *>(ar[2]);
  49. //LeftImage->campos = RenderPosition::LEFT;
  50. engine->rootContext()->setContextProperty("LeftImage", LeftImage);
  51. engine->addImageProvider(QLatin1String("LeftImage"),
  52. LeftImage->m_pImgProvider);
  53. // Right Cam
  54. ShowImage *RightImage = static_cast<ShowImage *>(ar[3]);
  55. //RightImage->campos = RenderPosition::RIGHT;
  56. engine->rootContext()->setContextProperty("RightImage", RightImage);
  57. engine->addImageProvider(QLatin1String("RightImage"),
  58. RightImage->m_pImgProvider);
  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. viewer.setTitle(QStringLiteral("Hyper vision remote control System"));
  80. viewer.setSource(QUrl("qrc:///main.qml"));
  81. viewer.setResizeMode(QQuickView::SizeRootObjectToView);
  82. QObject *item = viewer.rootObject();
  83. auto object = item->findChild<QObject*>("tst");
  84. if (object==nullptr)
  85. {
  86. qDebug() << "ColorSetting failed\n";
  87. }
  88. AppModel* appModel = new AppModel(_notify, _control,object);
  89. viewer.rootContext()->setContextProperty("appModel", appModel);
  90. QObject::connect(item, SIGNAL(qmlSignalMaxWindow()), &viewer, SLOT(show()));
  91. QObject::connect(item, SIGNAL(qmlSignalQuit()), appModel, SLOT(OnClose()));
  92. viewer.setFlags(Qt::FramelessWindowHint | Qt::Window);
  93. viewer.showMinimized();
  94. return app.exec();
  95. }
  96. /*
  97. long exceptionHander(_EXCEPTION_POINTERS* excp)
  98. {
  99. TCHAR m_szDumpPath[_MAX_PATH];
  100. TCHAR m_szAppPath[_MAX_PATH];
  101. TCHAR m_szAppBaseName[_MAX_PATH];
  102. time_t m_lTime;
  103. time(&m_lTime);
  104. LONG retval = EXCEPTION_CONTINUE_SEARCH;
  105. HMODULE hDll = NULL;
  106. //TCHAR szDbgHelpPath[_MAX_PATH];
  107. if (GetModuleFileName(NULL, m_szAppPath, _MAX_PATH))
  108. {
  109. TCHAR* pSlash = _tcsrchr(m_szAppPath, '\\');
  110. if (pSlash)
  111. {
  112. _tcsncpy_s(m_szAppBaseName, _MAX_PATH, pSlash + 1, _MAX_PATH);
  113. *(pSlash + 1) = 0;
  114. // SetDumpFileName
  115. wsprintf(m_szDumpPath, _T("%s%s.%ld.dmp"), m_szAppPath, m_szAppBaseName, m_lTime);
  116. }
  117. }
  118. TCHAR szScratch[USER_DATA_BUFFER_SIZE];
  119. // ask the user if they want to save a dump file
  120. wsprintf(szScratch, _T("There was an unexpected error:\n\n%s\nWould you like to save a diagnostic file?\n\nFilename: %s"), "", m_szDumpPath);
  121. if (::MessageBox(NULL, szScratch, NULL, MB_YESNO) != IDYES)
  122. return EXCEPTION_EXECUTE_HANDLER;
  123. //创建转储文件
  124. HANDLE hFile = CreateFile(m_szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
  125. CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  126. LPCTSTR szResult = NULL;
  127. if (hFile != INVALID_HANDLE_VALUE)
  128. {
  129. MINIDUMP_EXCEPTION_INFORMATION exptInfo;
  130. exptInfo.ThreadId = ::GetCurrentThreadId();
  131. exptInfo.ExceptionPointers = excp;
  132. exptInfo.ClientPointers = NULL;
  133. //将dump信息写入到文件中
  134. BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(),
  135. GetCurrentProcessId(),
  136. hFile, MiniDumpNormal,
  137. &exptInfo, NULL, NULL);
  138. if (bOK)
  139. {
  140. szResult = NULL;
  141. retval = EXCEPTION_EXECUTE_HANDLER;
  142. }
  143. else
  144. {
  145. wsprintf(szScratch, _T("Failed to save dump file to '%s' (error %d)"), m_szDumpPath, GetLastError());
  146. szResult = szScratch;
  147. }
  148. ::CloseHandle(hFile);
  149. }
  150. else
  151. {
  152. wsprintf(szScratch, _T("Failed to create dump file '%s' (error %d)"), m_szDumpPath, GetLastError());
  153. szResult = szScratch;
  154. }
  155. if (szResult)
  156. ::MessageBox(NULL, szResult, NULL, MB_OK);
  157. TerminateProcess(GetCurrentProcess(), 0);
  158. return EXCEPTION_CONTINUE_SEARCH;
  159. }
  160. */