From 41d37407e80f5ccd110cf303c20a181f95fa7e73 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Fri, 21 Jan 2022 16:01:35 +0100 Subject: Make singleton teardown work with Qt6 as well In Qt6 the Q_GLOBAL_STATIC will already report to be null while it is in the process of being deleted, we therefore cannot access it anymore from destruction code path as we did before. This problem is hit for example by the Breeze style, making all 6 based widgets applications crash on exit without this. --- src/kconfig_compiler/KConfigSourceGenerator.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/kconfig_compiler/KConfigSourceGenerator.cpp') diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index d83c1bb4..9071b9a4 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -138,7 +138,7 @@ void KConfigSourceGenerator::createSingletonImplementation() stream() << '{' << '\n'; stream() << " public:\n"; stream() << " " << cfg().className << "Helper() : q(nullptr) {}\n"; - stream() << " ~" << cfg().className << "Helper() { delete q; }\n"; + stream() << " ~" << cfg().className << "Helper() { delete q; q = nullptr; }\n"; stream() << " " << cfg().className << "Helper(const " << cfg().className << "Helper&) = delete;\n"; stream() << " " << cfg().className << "Helper& operator=(const " << cfg().className << "Helper&) = delete;\n"; stream() << " " << cfg().className << " *q;\n"; @@ -616,7 +616,10 @@ void KConfigSourceGenerator::createDestructor() stream() << " delete d;\n"; } if (cfg().singleton) { - stream() << " s_global" << cfg().className << "()->q = nullptr;\n"; + const QString qgs = QLatin1String("s_global") + cfg().className; + stream() << " if (" << qgs << ".exists() && !" << qgs << ".isDestroyed()) {\n"; + stream() << " " << qgs << "()->q = nullptr;\n"; + stream() << " }\n"; } endScope(); stream() << '\n'; -- cgit v1.2.1