Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.1.0 , 5.2.0 Beta1
-
e8f1b9917008d978c29cda9a2b40b841bc7a9df4
Description
The Background:
I am developing a plugin which uses Qt. This plugin is not unloaded by the host system, so I run the "main" function of my plugin multiple times without reloading the dynamic libraries. This means I create/run/destroy a QCoreApplication multiple times.
Because of the directory structure in which the plugin lives I have created a qt.conf file to correctly set up the plugin folders for Qt.
I noticed the following bug in Qt:
- The first time I create and run the plugin everything works as expected.
- From the second time onwards the Qt build prefix is used and qt.conf is totally ignored
Some Source Code lookup, revealed this (qtbase/src/corelib/global/qlibraryinfo.cpp):
- When the plugin is run for the first time QLibrarySettings is constructed using the qt.conf file:
QLibrarySettings::QLibrarySettings() : settings(QLibraryInfoPrivate::findConfiguration())
- when QCoreApplication is destructed "qt_call_post_routines()" is called, which in turn calls:
static void cleanup() { QLibrarySettings *ls = qt_library_settings(); if (ls) ls->settings.reset(0); }
- This results in a valid QLibrarySettings object (but with settings==NULL) for the second run of the plugin. So the function
static QSettings *configuration() { QLibrarySettings *ls = qt_library_settings(); return ls ? ls->settings.data() : 0; }
returns a NULL pointer.
my suggestion:
changed the function to this:
static QSettings *configuration() { QLibrarySettings *ls = qt_library_settings(); if (!ls) return 0; if (!ls->settings) ls->settings.reset(findConfiguration()); return ls->settings.data(); }