EnergySpectrumAnalyer/src/GlobalDefine.h

68 lines
2.3 KiB
C++
Raw 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 GLOBALDEFINE_H
#define GLOBALDEFINE_H
#include "MainWindow.h"
#include "QsLog.h"
#include <QTextCodec>
#include <QRegularExpression>
#include <QDebug>
// 转换Qt字符串路径为系统编码的C字符串解决中文路径问题
static const char* QStrToSysPath(const QString& qstr_path)
{
static std::string sys_path; // 静态变量避免内存释放
#ifdef Q_OS_WIN
// Windows转为GBK编码
QTextCodec* gbkCodec = QTextCodec::codecForName("GBK");
if (!gbkCodec) gbkCodec = QTextCodec::codecForLocale();
sys_path = gbkCodec->fromUnicode(qstr_path).toStdString();
#else
// Linux/Mac转为UTF-8编码
sys_path = qstr_path.toUtf8().toStdString();
#endif
return sys_path.c_str();
}
static int ExtractNumberFromString(const QString& str) {
int ret_num = -1;
QRegularExpression regex("\\d+");
QRegularExpressionMatch match = regex.match(str);
if (match.hasMatch()) {
ret_num = match.captured().toInt();
}
return ret_num;
};
#define STATUS_BAR_MSG(msg) \
{ \
MainWindow::ShowStatusBarMsg(msg); \
}
#define LOG_INFO(out_info) \
{ \
MainWindow::OutputInfo(MainWindow::eInfo, out_info); \
QLOG_INFO() << out_info; \
}
#define LOG_WARN(warn_info) \
{ \
MainWindow::OutputInfo(MainWindow::eWarning, warn_info); \
QLOG_WARN() << warn_info; \
}
#define LOG_ERROR(error_info) \
{ \
MainWindow::OutputInfo(MainWindow::eError, error_info); \
QLOG_ERROR() << error_info; \
}
#define LOG_DEBUG(debug_info) \
{ \
MainWindow::OutputInfo(MainWindow::eDebug, debug_info); \
QLOG_DEBUG() << debug_info; \
}
#endif // GLOBALDEFINE_H