#include "CMainControl.h"
#include <QDebug>
#include <QCoreApplication>
#include <QDir>
#include <QApplication>
#include <QDesktopWidget>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QSettings>
#include <QByteArray>
#include <QCryptographicHash>
#include <QDateTime>
#include <QUuid>
CMainControl* CMainControl::m_pInstance = new CMainControl();
CMainControl::CMainControl(QObject *parent)
: QObject(parent)
, m_pMsgTaskThread(nullptr)
{
initConnect();
qDebug() << "CMainControl==============================";
}
CMainControl::~CMainControl()
{
qDebug() << "Destructor() ===============~CMainControl=";
stopMsgTask();
delete m_pMsgTaskThread;
m_pMsgTaskThread = nullptr;
}
void CMainControl::initData()
{
m_pMsgTaskThread = new CMessageQueueThread();
connect(m_pMsgTaskThread, &CMessageQueueThread::signalQueueWebSocketMessageData,
this, &CMainControl::slotParseMessageData, Qt::BlockingQueuedConnection);
//阻塞连接等slotParseMessageData函数执行完了再发下一个信号
m_pMsgTaskThread->start();
m_nDesktopWidth = QApplication::desktop()->width();
m_nDesktopHeight = QApplication::desktop()->height();
}
void CMainControl::slotParseMessageData(const QString &message)
{
qDebug()<<"CMainControl::slotParseMessageData:================" << message;
}
void CMainControl::slotAddQueueMessageData(const QString &message)
{
mutexM.lock();
qDebug()<<"CMainControl::slotAddQueueMessageData:==============message.size=====" << message.size();
m_qQueueMsg.enqueue(message);
m_waitCondition.notify_all();
mutexM.unlock();
}
void CMainControl::initConnect()
{
}
int CMainControl::getDesktopWidth()
{
return m_nDesktopWidth;
}
int CMainControl::getDesktopHeight()
{
return m_nDesktopHeight;
}
int CMainControl::getMessageCount()
{
return m_qQueueMsg.size();
}
void CMainControl::stopMsgTask()
{
if(!m_pMsgTaskThread||m_pMsgTaskThread->stopState())
return;
qDebug() << "CMainControl::stopMsgTask========================================" << __LINE__;
if(m_pMsgTaskThread)
m_pMsgTaskThread->stop();
m_waitCondition.notify_all();
m_qQueueMsg.clear();
m_pMsgTaskThread->deleteLater();
m_pMsgTaskThread = nullptr;
qDebug() << "CMainControl::stopMsgTask=======2=================================" << __LINE__;
}
评论10