Commit 9e1683e2 by ss.dai

修复小票不显示收银员 程序退出残留进程

parent 2dd7a65e
...@@ -17,16 +17,18 @@ void RefundControl::SetListenPort(int port) ...@@ -17,16 +17,18 @@ void RefundControl::SetListenPort(int port)
RefundControl::~RefundControl() RefundControl::~RefundControl()
{ {
m_bContinue = false;
m_mutex.lock();
QLOG_INFO() << __FUNCTION__ << m_bContinue;
} }
// 同步模式 // 同步模式
void RefundControl::run() void RefundControl::run()
{ {
m_mutex.lock();
m_procOrderSocket = new BillSocket(this); m_procOrderSocket = new BillSocket(this);
m_tcpServer = new QTcpServer(this); m_tcpServer = new QTcpServer(this);
qDebug() << 11 << m_tcpServer->serverError();
if(!m_tcpServer->listen(QHostAddress::LocalHost, m_port)) if(!m_tcpServer->listen(QHostAddress::LocalHost, m_port))
{ {
QLOG_WARN() << QString("tcp server listen failed on port[%1]").arg(m_port); QLOG_WARN() << QString("tcp server listen failed on port[%1]").arg(m_port);
...@@ -45,18 +47,12 @@ void RefundControl::run() ...@@ -45,18 +47,12 @@ void RefundControl::run()
while(m_bContinue) while(m_bContinue)
{ {
QLOG_INFO() << "waiting new connection...."; QLOG_INFO() << "waiting new connection....";
if(!m_tcpServer->waitForNewConnection(60000)) if(!m_tcpServer->waitForNewConnection(1000))
{ {
continue; continue;
} }
QLOG_INFO() << "onNewConnecion....."; QLOG_INFO() << "onNewConnecion.....";
// if(QAbstractSocket::UnknownSocketError != m_tcpServer->serverError())
// {
// QLOG_INFO() << QString("0socket error %1").arg(m_tcpServer->serverError().errorString());
// continue;
// }
// QLOG_INFO() << QString("1socket error %1").arg(m_tcpServer->serverError().errorString());
QString error; QString error;
QString orderId, reason; int version, reqtype; QString orderId, reason; int version, reqtype;
m_tcpSocket = m_tcpServer->nextPendingConnection(); m_tcpSocket = m_tcpServer->nextPendingConnection();
...@@ -130,5 +126,9 @@ void RefundControl::run() ...@@ -130,5 +126,9 @@ void RefundControl::run()
m_tcpSocket->close(); m_tcpSocket->close();
continue; continue;
} }
m_tcpServer->close();
m_tcpServer->deleteLater();
m_mutex.unlock();
QLOG_INFO() << "refundControl exit."; QLOG_INFO() << "refundControl exit.";
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <QObject> #include <QObject>
#include <QTcpServer> #include <QTcpServer>
#include <QTcpSocket> #include <QTcpSocket>
#include <QMutex>
#include "Network/billSocket.h" #include "Network/billSocket.h"
class RefundControl : public QObject class RefundControl : public QObject
...@@ -26,6 +27,7 @@ private: ...@@ -26,6 +27,7 @@ private:
QTcpSocket *m_tcpSocket; QTcpSocket *m_tcpSocket;
int m_port; int m_port;
bool m_bContinue; bool m_bContinue;
QMutex m_mutex;
BillSocket *m_procOrderSocket; BillSocket *m_procOrderSocket;
......
#include "SysTray.h" #include "SysTray.h"
#include <QApplication> #include <QApplication>
#include <QThread>
extern QThread workThread;
extern QThread refundThread;
SysTray::SysTray(QObject *parent) : SysTray::SysTray(QObject *parent) :
QSystemTrayIcon(parent) QSystemTrayIcon(parent)
...@@ -22,5 +27,7 @@ void SysTray::_CreatMenu() ...@@ -22,5 +27,7 @@ void SysTray::_CreatMenu()
void SysTray::onActionQuitTriggered() void SysTray::onActionQuitTriggered()
{ {
qApp->exit(); workThread.terminate();
refundThread.terminate();
qApp->exit(-1);
} }
...@@ -16,6 +16,9 @@ using namespace QsLogging; ...@@ -16,6 +16,9 @@ using namespace QsLogging;
QString g_appDir; QString g_appDir;
QThread workThread;
QThread refundThread;
void InitLogger() void InitLogger()
{ {
QString logDir = QString("%1/log").arg(g_appDir); QString logDir = QString("%1/log").arg(g_appDir);
...@@ -70,12 +73,12 @@ int main(int argc, char *argv[]) ...@@ -70,12 +73,12 @@ int main(int argc, char *argv[])
QLOG_INFO() << QString("-------- fmTakeaway[%1] Start --------").arg(APP_VERSION); QLOG_INFO() << QString("-------- fmTakeaway[%1] Start --------").arg(APP_VERSION);
// 将控制器移到工作线程 // 将控制器移到工作线程
QThread workThread;
FlowControl::GetInstance().moveToThread(&workThread); FlowControl::GetInstance().moveToThread(&workThread);
workThread.start(); workThread.start();
// 将退款控制器移到工作线程 // 将退款控制器移到工作线程
QThread refundThread;
RefundControl::GetInstance().SetListenPort(ConfigManger::GetInstance().GetListenPort()); RefundControl::GetInstance().SetListenPort(ConfigManger::GetInstance().GetListenPort());
RefundControl::GetInstance().moveToThread(&refundThread); RefundControl::GetInstance().moveToThread(&refundThread);
QObject::connect(&refundThread, &QThread::started, &RefundControl::GetInstance(), &RefundControl::run); QObject::connect(&refundThread, &QThread::started, &RefundControl::GetInstance(), &RefundControl::run);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment