| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include <QtWidgets/QApplication>
- #include "TaskMNG.h"
- #include "TeachCMDReadThread.h"
- #include "QThreadHttpServer.h"
- #include "DataManager.h"
- #include "Widget_HttpSendJson.h"
- #include "QThreadHttpClient.h"
- #include "CMDReadThread.h"
- #include "AsioUDPNetDLL.h"
- #include <QDebug>
- //#include "ydtray.h"
- #define READ_INI_STR(key, default_value) (settings.contains(key) ? settings.value(key).toString() : default_value)
- #define READ_INI_INT(key, default_value) (settings.contains(key) ? settings.value(key).toInt() : default_value)
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- // 设置应用程序信息
- //app.setApplicationVersion("1.0");
- app.setQuitOnLastWindowClosed(false); // 重要:当最后一个窗口关闭时不退出应用
- NetDll_LibraryInit();
- NetDll_InitUDPNet();
- /*
- #ifdef IN_WINDOWS
- std::string Str_Dll = GetFolder_Module_2() + "\\ElectricityVOC.dll";
- #else
- std::string Str_Dll = GetFolder_Module_2() + "libElectricityVOC.so";
- #endif*/
- QString pAddress = QCoreApplication::applicationDirPath() + "/config";
- QSettings settings(pAddress, QSettings::IniFormat);
- settings.setIniCodec("UTF-8"); // 支持中文
- QString strIP = READ_INI_STR("DBData/IP", "127.0.0.1");
- QString strBDName = READ_INI_STR("DBData/DBName", "CCGD_Project");
- QString strUser = READ_INI_STR("DBData/User", "dbadmin");
- QString strPWD = READ_INI_STR("DBData/PWD", "dbadmin@987");
- int nType = READ_INI_INT("DBData/DBType", 0);
- // strIP = settings.value("DBData/IP", 120).toString();
- // strName = settings.value("DBData/DBName", 220).toString();
- TaskMNG::instance()->InitDB(strIP.toStdString(), nType,strBDName.toStdString(), strUser.toStdString(),strPWD.toStdString());
-
- CMDReadThread* pOCCThread = new CMDReadThread();
- NetDll_SetNetQueue(pOCCThread->getNetQueue());
- NetDll_StartThread();
- pOCCThread->start();
- TeachCMDReadThread* pThread = new TeachCMDReadThread(nullptr);
- pThread->setNetQueue(&TaskMNG::instance()->m_pSendList, &TaskMNG::instance()->m_pRecvList);
-
- pThread->start();
- Widget_HttpSendJson window;
- //ydTray::installTray(&window);
- window.show();
- //
- QThreadHttpServer* pServerThread = new QThreadHttpServer(nullptr);
- QThreadHttpClient::instance().InitConnect(pThread);
- QThreadHttpClient::instance().initHttpClient();
- QString strHost = "";
- int nPort = 0;
- QString strGetPath=QApplication::applicationDirPath();
- strGetPath.append("/config");
- //QSettings settings(strGetPath,QSettings::IniFormat);
- //settings.setPath(strGetPath);
- settings.setIniCodec("UTF-8");
- strHost = READ_INI_STR("HttpServer/IP", "192.168.81.130");
- nPort = READ_INI_INT("HttpServer/port", 6090);
- qDebug() << "Server IP:" << strHost << " Port:" << nPort;
- pServerThread->setIPPost(strHost, nPort);
- pServerThread->InitHttpServer();
- pServerThread->start();
- //window.hide();
- int nRet = app.exec();
- NetDll_StopThread();
- NetDll_LibraryCleanup();
- //ydTray::unstallTray();
- pServerThread->StopThread();
- pServerThread->wait();
- delete pServerThread;
- pServerThread=nullptr;
- pOCCThread->stopImmediately();
- pOCCThread->wait();
- delete pOCCThread;
- NetDll_DestroyUDPNet();
- QThreadHttpClient::destroyInstance();
- return nRet;
- }
|