Added the qt_registry_cleanup() function. Will be called via atexit() on application shutdown.

This commit is contained in:
LoRd_MuldeR 2015-10-18 16:09:25 +02:00
parent 415d385f86
commit d4153ce243

View File

@ -24,6 +24,7 @@
#include <MUtils/OSSupport.h> #include <MUtils/OSSupport.h>
#include <MUtils/Terminal.h> #include <MUtils/Terminal.h>
#include <MUtils/ErrorHandler.h> #include <MUtils/ErrorHandler.h>
#include <MUtils/Registry.h>
#include <MUtils/Exception.h> #include <MUtils/Exception.h>
//Qt //Qt
@ -37,6 +38,9 @@
#include <QMessageBox> #include <QMessageBox>
#include <QtPlugin> #include <QtPlugin>
//CRT
#include <string.h>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Qt Static Initialization // Qt Static Initialization
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -201,6 +205,28 @@ static QString getExecutableName(int &argc, char **argv)
return QLatin1String("Program.exe"); 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) QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &appName)
{ {
QMutexLocker lock(&g_init_lock); QMutexLocker lock(&g_init_lock);
@ -236,7 +262,6 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &
#endif #endif
//Check the Windows version //Check the Windows version
const MUtils::OS::Version::os_version_t &osVersion = MUtils::OS::os_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)) 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 //Create Qt application instance
QApplication *application = new QApplication(argc, argv); QApplication *application = new QApplication(argc, argv);
//Register the Qt clean-up function
atexit(qt_registry_cleanup);
//Load plugins from application directory //Load plugins from application directory
QCoreApplication::setLibraryPaths(QStringList() << QApplication::applicationDirPath()); QCoreApplication::setLibraryPaths(QStringList() << QApplication::applicationDirPath());
qDebug("Library Path:\n%s\n", MUTILS_UTF8(QApplication::libraryPaths().first())); qDebug("Library Path:\n%s\n", MUTILS_UTF8(QApplication::libraryPaths().first()));