From b58347f7ebc5b6c6005bcf473b15fab600da5b0c Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 1 Jan 2015 21:34:24 +0100 Subject: [PATCH] Implemented static resource initialization. --- MUtilities_VS2013.vcxproj | 4 +-- MUtilities_VS2013.vcxproj.filters | 8 +++--- res/{Resource.qrc => MUtilsData.qrc} | 0 src/Startup.cpp | 41 ++++++++++++++++++++++++++-- 4 files changed, 45 insertions(+), 8 deletions(-) rename res/{Resource.qrc => MUtilsData.qrc} (100%) diff --git a/MUtilities_VS2013.vcxproj b/MUtilities_VS2013.vcxproj index f0fa6c3..89f6468 100644 --- a/MUtilities_VS2013.vcxproj +++ b/MUtilities_VS2013.vcxproj @@ -15,7 +15,7 @@ - + @@ -72,7 +72,7 @@ - + Document "$(QTDIR)\bin\rcc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" -name "%(Filename)" "%(FullPath)" "$(QTDIR)\bin\rcc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\QRC_%(Filename).cpp" -name "%(Filename)" "%(FullPath)" diff --git a/MUtilities_VS2013.vcxproj.filters b/MUtilities_VS2013.vcxproj.filters index 05c2d70..c7a6ad8 100644 --- a/MUtilities_VS2013.vcxproj.filters +++ b/MUtilities_VS2013.vcxproj.filters @@ -63,9 +63,6 @@ Source Files\3rd Party - - Source Files\Generated - Source Files\Generated @@ -90,6 +87,9 @@ Source Files + + Source Files\Generated + @@ -160,7 +160,7 @@ Public Headers - + Resource Files diff --git a/res/Resource.qrc b/res/MUtilsData.qrc similarity index 100% rename from res/Resource.qrc rename to res/MUtilsData.qrc diff --git a/src/Startup.cpp b/src/Startup.cpp index 7524560..f44c448 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -38,10 +38,11 @@ #include /////////////////////////////////////////////////////////////////////////////// -// Qt Plugin Initialization +// Qt Static Initialization /////////////////////////////////////////////////////////////////////////////// #ifdef QT_NODLL + #if QT_VERSION < QT_VERSION_CHECK(5,0,0) Q_IMPORT_PLUGIN(qico) Q_IMPORT_PLUGIN(qsvg) @@ -49,7 +50,43 @@ Q_IMPORT_PLUGIN(qsvg) Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) Q_IMPORT_PLUGIN(QICOPlugin) #endif -#endif + +static void doInitializeResources(void) +{ + Q_INIT_RESOURCE(MUtilsData); +} + +static void doCleanupResources(void) +{ + Q_CLEANUP_RESOURCE(MUtilsData); +} + +namespace MUtils +{ + namespace Startup + { + namespace Internal + { + class ResourceInitializer + { + public: + ResourceInitializer(void) + { + doInitializeResources(); + } + + ~ResourceInitializer(void) + { + doCleanupResources(); + } + }; + + static ResourceInitializer resourceInitializer; + } + } +} + +#endif //QT_NODLL /////////////////////////////////////////////////////////////////////////////// // MESSAGE HANDLER