64 lines
1.0 KiB
C++
64 lines
1.0 KiB
C++
|
|
#include <QString>
|
|
#include <QMap>
|
|
#include <QObject>
|
|
#include "QtToWebFunction.h"
|
|
#include <thread>
|
|
#include <atomic>
|
|
|
|
|
|
QtToWebThread::QtToWebThread()
|
|
{
|
|
m_running = true;
|
|
m_Thread = std::thread(&QtToWebThread::threadFunction, this);
|
|
}
|
|
|
|
QtToWebThread::~QtToWebThread()
|
|
{
|
|
m_running = false;
|
|
if (m_Thread.joinable())
|
|
{
|
|
m_Thread.join(); // 等待子线程完成
|
|
}
|
|
}
|
|
|
|
// 子线程的工作函数:模拟日志输出
|
|
void QtToWebThread::threadFunction()
|
|
{
|
|
while (m_running)
|
|
{
|
|
QtToWebData result;
|
|
if (QtToWebFunction::getInstance().dequeue(result))
|
|
{
|
|
ccsMessageHandle::instance()->qt2web(result.cmd, result.iState, result.message, result.data);
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50)); // 添加延时,避免占用过多资源
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
QtToWebFunction& QtToWebFunction::getInstance()
|
|
{
|
|
static QtToWebFunction instance;
|
|
return instance;
|
|
}
|
|
|
|
QtToWebFunction::QtToWebFunction()
|
|
{
|
|
|
|
}
|
|
|
|
QtToWebFunction::~QtToWebFunction()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|