You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
931 B
69 lines
931 B
10 months ago
|
## 概述
|
||
|
|
||
|
- Singleton.h
|
||
|
|
||
|
懒汉模式的单例模板类
|
||
|
|
||
|
- loghandler.h/cpp
|
||
|
|
||
|
日志类
|
||
|
|
||
|
- MyLogger.pri
|
||
|
|
||
|
子模块qt pri文件
|
||
|
|
||
|
## 使用
|
||
|
|
||
|
### 克隆代码
|
||
|
|
||
|
克隆代码并复制到工程Libs目录下
|
||
|
|
||
|
### 添加子工程
|
||
|
|
||
|
在主工程pro文件中,添加:
|
||
|
|
||
|
```pro
|
||
|
include($$PWD/Libs/MyLogger/MyLogger.pri)
|
||
|
```
|
||
|
|
||
|
### 使用
|
||
|
|
||
|
#### 日志使用
|
||
|
|
||
|
```c++
|
||
|
#include <QApplication>
|
||
|
//头文件
|
||
|
#include "loghandler.h"
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
QApplication a(argc, argv);
|
||
|
//安装
|
||
|
LogHandler::Get().installMessageHandler();
|
||
|
Debug() << "Hello";
|
||
|
qDebug() << "当前时间是: " << QTime::currentTime().toString("hh:mm:ss");
|
||
|
qInfo() << QString("God bless you!");
|
||
|
//卸载
|
||
|
LogHandler::Get().uninstallMessageHandler();
|
||
|
return a.exec();
|
||
|
}
|
||
|
```
|
||
|
|
||
|
|
||
|
|
||
|
#### 单例模板类使用
|
||
|
|
||
|
```c++
|
||
|
#include "Singleton.h"
|
||
|
class AppConfig : public QObject
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
//通过宏
|
||
|
SINGLETON(AppConfig);
|
||
|
.....
|
||
|
}
|
||
|
|
||
|
```
|
||
|
|
||
|
|
||
|
|