diff options
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 3 | ||||
-rw-r--r-- | src/widgets/util/qcolormap.cpp | 16 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 8a041a4ac2c..82ecd355baf 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -31,7 +31,6 @@ #include <private/qdnd_p.h> #endif #include "private/qguiapplication_p.h" -#include "qcolormap.h" #include "qdebug.h" #if QT_CONFIG(style_stylesheet) #include "private/qstylesheetstyle_p.h" @@ -480,7 +479,6 @@ void QApplicationPrivate::init() process_cmdline(); // Must be called before initialize() - QColormap::initialize(); initializeWidgetPalettesFromTheme(); qt_init_tooltip_palette(); QApplicationPrivate::initializeWidgetFontHash(); @@ -712,7 +710,6 @@ QApplication::~QApplication() d->cleanupMultitouch(); QPixmapCache::clear(); - QColormap::cleanup(); QApplicationPrivate::active_window = nullptr; //### this should not be necessary diff --git a/src/widgets/util/qcolormap.cpp b/src/widgets/util/qcolormap.cpp index 08f892b109c..dfd32fd9816 100644 --- a/src/widgets/util/qcolormap.cpp +++ b/src/widgets/util/qcolormap.cpp @@ -7,6 +7,8 @@ #include "qscreen.h" #include "qguiapplication.h" +#include <QtCore/qmutex.h> + QT_BEGIN_NAMESPACE class QColormapPrivate @@ -42,16 +44,26 @@ void QColormap::initialize() screenMap->mode = QColormap::Direct; screenMap->numcolors = -1; } + + qAddPostRoutine(QColormap::cleanup); } void QColormap::cleanup() { - delete screenMap; - screenMap = nullptr; + if (screenMap) { + if (!screenMap->ref.deref()) + delete screenMap; + screenMap = nullptr; + } } QColormap QColormap::instance(int /*screen*/) { + static QMutex mutex; + QMutexLocker locker(&mutex); + if (!screenMap) + initialize(); + return QColormap(); } |