main.cpp 6.2 KB

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