main.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <QtWidgets/QApplication>
  2. #include "TaskMNG.h"
  3. #include "TeachCMDReadThread.h"
  4. #include "QThreadHttpServer.h"
  5. #include "DataManager.h"
  6. #include "Widget_HttpSendJson.h"
  7. #include "QThreadHttpClient.h"
  8. #include "CMDReadThread.h"
  9. #include "AsioUDPNetDLL.h"
  10. #include <QDebug>
  11. //#include "ydtray.h"
  12. #define READ_INI_STR(key, default_value) (settings.contains(key) ? settings.value(key).toString() : default_value)
  13. #define READ_INI_INT(key, default_value) (settings.contains(key) ? settings.value(key).toInt() : default_value)
  14. int main(int argc, char *argv[])
  15. {
  16. QApplication app(argc, argv);
  17. // 设置应用程序信息
  18. //app.setApplicationVersion("1.0");
  19. app.setQuitOnLastWindowClosed(false); // 重要:当最后一个窗口关闭时不退出应用
  20. NetDll_LibraryInit();
  21. NetDll_InitUDPNet();
  22. /*
  23. #ifdef IN_WINDOWS
  24. std::string Str_Dll = GetFolder_Module_2() + "\\ElectricityVOC.dll";
  25. #else
  26. std::string Str_Dll = GetFolder_Module_2() + "libElectricityVOC.so";
  27. #endif*/
  28. QString pAddress = QCoreApplication::applicationDirPath() + "/config";
  29. QSettings settings(pAddress, QSettings::IniFormat);
  30. settings.setIniCodec("UTF-8"); // 支持中文
  31. QString strIP = READ_INI_STR("DBData/IP", "127.0.0.1");
  32. QString strBDName = READ_INI_STR("DBData/DBName", "CCGD_Project");
  33. QString strUser = READ_INI_STR("DBData/User", "dbadmin");
  34. QString strPWD = READ_INI_STR("DBData/PWD", "dbadmin@987");
  35. int nType = READ_INI_INT("DBData/DBType", 0);
  36. // strIP = settings.value("DBData/IP", 120).toString();
  37. // strName = settings.value("DBData/DBName", 220).toString();
  38. TaskMNG::instance()->InitDB(strIP.toStdString(), nType,strBDName.toStdString(), strUser.toStdString(),strPWD.toStdString());
  39. CMDReadThread* pOCCThread = new CMDReadThread();
  40. NetDll_SetNetQueue(pOCCThread->getNetQueue());
  41. NetDll_StartThread();
  42. pOCCThread->start();
  43. TeachCMDReadThread* pThread = new TeachCMDReadThread(nullptr);
  44. pThread->setNetQueue(&TaskMNG::instance()->m_pSendList, &TaskMNG::instance()->m_pRecvList);
  45. pThread->start();
  46. Widget_HttpSendJson window;
  47. //ydTray::installTray(&window);
  48. window.show();
  49. //
  50. QThreadHttpServer* pServerThread = new QThreadHttpServer(nullptr);
  51. QThreadHttpClient::instance().InitConnect(pThread);
  52. QThreadHttpClient::instance().initHttpClient();
  53. QString strHost = "";
  54. int nPort = 0;
  55. QString strGetPath=QApplication::applicationDirPath();
  56. strGetPath.append("/config");
  57. //QSettings settings(strGetPath,QSettings::IniFormat);
  58. //settings.setPath(strGetPath);
  59. settings.setIniCodec("UTF-8");
  60. strHost = READ_INI_STR("HttpServer/IP", "192.168.81.130");
  61. nPort = READ_INI_INT("HttpServer/port", 6090);
  62. qDebug() << "Server IP:" << strHost << " Port:" << nPort;
  63. pServerThread->setIPPost(strHost, nPort);
  64. pServerThread->InitHttpServer();
  65. pServerThread->start();
  66. //window.hide();
  67. int nRet = app.exec();
  68. NetDll_StopThread();
  69. NetDll_LibraryCleanup();
  70. //ydTray::unstallTray();
  71. pServerThread->StopThread();
  72. pServerThread->wait();
  73. delete pServerThread;
  74. pServerThread=nullptr;
  75. pOCCThread->stopImmediately();
  76. pOCCThread->wait();
  77. delete pOCCThread;
  78. NetDll_DestroyUDPNet();
  79. QThreadHttpClient::destroyInstance();
  80. return nRet;
  81. }