Browse Source

modify

master
tianzhendong 4 months ago
parent
commit
d366556106
  1. 27
      MyLogger.pro
  2. 48
      Singleton.h
  3. 12
      loghandler.cpp
  4. 14
      loghandler.h

27
MyLogger.pro

@ -0,0 +1,27 @@
QT += core
TEMPLATE = lib
DEFINES += MYLOGGER_LIBRARY
CONFIG += c++17
INCLUDEPATH += $$PWD/
DESTDIR = $$PWD/../../Build/Libs
MOC_DIR = $$PWD/Build/moc
OBJECTS_DIR = $$PWD/Build/objs
RCC_DIR = $$PWD/Build/resources
UI_DIR = $$PWD/Build/ui
#在release下输出debug信息
DEFINES += QT_MESSAGELOGCONTEXT
HEADERS += \
$$PWD/loghandler.h
SOURCES += \
$$PWD/loghandler.cpp
unix {
target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target

48
Singleton.h

@ -52,24 +52,24 @@ private:
/// ///
////////////////////////////////////////////////////////////////////////////////
#if 0
//template <typename T> QMutex Singleton<T>::mutex;
//template <typename T> QScopedPointer<T> Singleton<T>::instance;
template <typename T> QMutex Singleton<T>::mutex;
template <typename T> QScopedPointer<T> Singleton<T>::instance;
//template <typename T>
//T& Singleton<T>::getInstance()
//{
// if (instance.isNull())
// {
// mutex.lock();
// if (instance.isNull())
// {
// instance.reset(new T());
// }
// mutex.unlock();
// }
template <typename T>
T& Singleton<T>::getInstance()
{
if (instance.isNull())
{
mutex.lock();
if (instance.isNull())
{
instance.reset(new T());
}
mutex.unlock();
}
// return *instance.data();
//}
return *instance.data();
}
#endif
////////////////////////////////////////////////////////////////////////////////
@ -78,14 +78,14 @@ private:
/// ///
////////////////////////////////////////////////////////////////////////////////
#if 0
//#define SINGLETON(Class) \
//private: \
// Class(); \
// ~Class(); \
// Class(const Class &other); \
// Class& operator=(const Class &other); \
// friend class Singleton<Class>; \
// friend struct QScopedPointerDeleter<Class>;
#define SINGLETON(Class) \
private: \
Class(); \
~Class(); \
Class(const Class &other); \
Class& operator=(const Class &other); \
friend class Singleton<Class>; \
friend struct QScopedPointerDeleter<Class>;
#endif
#define SINGLETON(Class) friend class Singleton<Class>
#endif // SINGLETON_H

12
loghandler.cpp

@ -1,5 +1,15 @@
#include "loghandler.h"
#include <iostream>
#include <QDebug>
#include <QDateTime>
#include <QMutexLocker>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QTimer>
#include <QTextStream>
#include <QTextCodec>
#include "Singleton.h"
#include <QCoreApplication>
QMutex g_mutex;

14
loghandler.h

@ -1,19 +1,9 @@
#ifndef LOGHANDLER_H
#define LOGHANDLER_H
#include <iostream>
#include <QDebug>
#include <QDateTime>
#include <QMutexLocker>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QTimer>
#include <QTextStream>
#include <QTextCodec>
#include "Singleton.h"
#include <QObject>
class LogHandler
class Q_DECL_EXPORT LogHandler
{
public:
void installMessageHandler(); // 给Qt安装消息处理函数

Loading…
Cancel
Save