From d4153ce243c6595595a905bd660947d1f0a8e57c Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 18 Oct 2015 16:09:25 +0200 Subject: [PATCH] Added the qt_registry_cleanup() function. Will be called via atexit() on application shutdown. --- src/Startup.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Startup.cpp b/src/Startup.cpp index b656582..b4295bc 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include //Qt @@ -37,6 +38,9 @@ #include #include +//CRT +#include + /////////////////////////////////////////////////////////////////////////////// // Qt Static Initialization /////////////////////////////////////////////////////////////////////////////// @@ -201,6 +205,28 @@ static QString getExecutableName(int &argc, char **argv) return QLatin1String("Program.exe"); } +static void qt_registry_cleanup(void) +{ + static const wchar_t *const KEYS[] = + { + L"Software\\Trolltech\\OrganizationDefaults\\Qt Factory Cache %s\\com.trolltech.Qt.QImageIOHandlerFactoryInterface:", + L"Software\\Trolltech\\OrganizationDefaults\\Qt Plugin Cache %s.false", + NULL + }; + + wchar_t version[32]; + _snwprintf_s(version, 32, _TRUNCATE, L"%u.%u", (QT_VERSION >> 16), ((QT_VERSION >> 8) & 0xFF)); + + for(size_t i = 0; KEYS[i]; i++) + { + wchar_t key[256]; + if(_snwprintf_s(key, 256, _TRUNCATE, KEYS[i], version) > 0) + { + MUtils::Registry::reg_key_delete(MUtils::Registry::root_user, MUTILS_QSTR(key)); + } + } +} + QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &appName) { QMutexLocker lock(&g_init_lock); @@ -236,7 +262,6 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString & #endif //Check the Windows version - const MUtils::OS::Version::os_version_t &osVersion = MUtils::OS::os_version(); if((osVersion.type != MUtils::OS::Version::OS_WINDOWS) || (osVersion < MUtils::OS::Version::WINDOWS_WINXP)) { @@ -278,6 +303,9 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString & //Create Qt application instance QApplication *application = new QApplication(argc, argv); + //Register the Qt clean-up function + atexit(qt_registry_cleanup); + //Load plugins from application directory QCoreApplication::setLibraryPaths(QStringList() << QApplication::applicationDirPath()); qDebug("Library Path:\n%s\n", MUTILS_UTF8(QApplication::libraryPaths().first()));