diff --git a/MyLogger.pro b/MyLogger.pro new file mode 100644 index 0000000..defa22a --- /dev/null +++ b/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 diff --git a/Singleton.h b/Singleton.h index d23e7c1..2fa8191 100644 --- a/Singleton.h +++ b/Singleton.h @@ -52,24 +52,24 @@ private: /// /// //////////////////////////////////////////////////////////////////////////////// #if 0 -//template QMutex Singleton::mutex; -//template QScopedPointer Singleton::instance; +template QMutex Singleton::mutex; +template QScopedPointer Singleton::instance; -//template -//T& Singleton::getInstance() -//{ -// if (instance.isNull()) -// { -// mutex.lock(); -// if (instance.isNull()) -// { -// instance.reset(new T()); -// } -// mutex.unlock(); -// } +template +T& Singleton::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; \ -// friend struct QScopedPointerDeleter; +#define SINGLETON(Class) \ +private: \ + Class(); \ + ~Class(); \ + Class(const Class &other); \ + Class& operator=(const Class &other); \ + friend class Singleton; \ + friend struct QScopedPointerDeleter; #endif #define SINGLETON(Class) friend class Singleton #endif // SINGLETON_H diff --git a/loghandler.cpp b/loghandler.cpp index fdba705..4e8fa04 100644 --- a/loghandler.cpp +++ b/loghandler.cpp @@ -1,5 +1,15 @@ #include "loghandler.h" - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Singleton.h" #include QMutex g_mutex; diff --git a/loghandler.h b/loghandler.h index 5a5597f..2e45b14 100644 --- a/loghandler.h +++ b/loghandler.h @@ -1,19 +1,9 @@ #ifndef LOGHANDLER_H #define LOGHANDLER_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "Singleton.h" +#include -class LogHandler +class Q_DECL_EXPORT LogHandler { public: void installMessageHandler(); // 给Qt安装消息处理函数