This repository has been archived on 2026-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
SP713_CPP_QT/drivers/log/logHandler.h
2025-07-17 13:10:47 +08:00

32 lines
879 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __LOG_HANDLER_H__
#define __LOG_HANDLER_H__
#include <QObject>
#include <QPlainTextEdit>
#include <QMutex>
class LogHandler : public QObject {
Q_OBJECT
public:
// 获取单例实例
static LogHandler* log_instance();
// 初始化日志输出目标UI控件
static void log_init(QPlainTextEdit *logWidget = nullptr);
// Qt 消息处理函数(静态)
static void log_handleMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg);
signals:
// 日志信号(用于跨线程传递)
void log_messageLogged(const QString &formattedMsg);
private:
explicit LogHandler(QObject *parent = nullptr);
static LogHandler *s_instance; // 单例实例
static QMutex s_mutex; // 线程安全锁
QPlainTextEdit *m_logWidget; // 日志输出UI组件
};
#endif