main.cpp 6.3 KB

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