diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-27 10:21:14 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-06-02 00:42:51 +0000 |
commit | 7bfbd706b56c426e2683e519543b56426310520f (patch) | |
tree | 37e64901634cf65cd988be2f511c87bf2a8824b3 /src/qml/debugger | |
parent | 130eafa75bed2c4f0c72e2f4e4402b86837e153f (diff) |
qqmldebug.h: Wrap the QML debugging enabler into an unnamed namespace
This way compilers will hopefully not complain about the use of global
constructors anymore. It's clear now that we want a separate
QQmlDebuggingEnabler for each CU.
Change-Id: Ief8e748a87612c04a8ca9a8535f10d905675b918
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/qml/debugger')
-rw-r--r-- | src/qml/debugger/qqmldebug.cpp | 7 | ||||
-rw-r--r-- | src/qml/debugger/qqmldebug.h | 21 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/qml/debugger/qqmldebug.cpp b/src/qml/debugger/qqmldebug.cpp index 4044612793..c5f0555242 100644 --- a/src/qml/debugger/qqmldebug.cpp +++ b/src/qml/debugger/qqmldebug.cpp @@ -59,13 +59,18 @@ QT_BEGIN_NAMESPACE Q_CONSTINIT static std::atomic_flag s_printedWarning = Q_ATOMIC_FLAG_INIT; -QQmlDebuggingEnabler::QQmlDebuggingEnabler(bool printWarning) +void QQmlDebuggingEnabler::enableDebugging(bool printWarning) { if (printWarning && !s_printedWarning.test_and_set(std::memory_order_relaxed)) fprintf(stderr, "QML debugging is enabled. Only use this in a safe environment.\n"); QQmlEnginePrivate::qml_debugging_enabled.store(true, std::memory_order_relaxed); } +QQmlDebuggingEnabler::QQmlDebuggingEnabler(bool printWarning) +{ + enableDebugging(printWarning); +}; + /*! * Retrieves the plugin keys of the debugger services provided by default. The debugger services * enable a debug client to use a Qml/JavaScript debugger, in order to set breakpoints, pause diff --git a/src/qml/debugger/qqmldebug.h b/src/qml/debugger/qqmldebug.h index d2a0570423..095670a03b 100644 --- a/src/qml/debugger/qqmldebug.h +++ b/src/qml/debugger/qqmldebug.h @@ -56,7 +56,13 @@ struct Q_QML_EXPORT QQmlDebuggingEnabler WaitForClient }; + static void enableDebugging(bool printWarning); + +#if QT_DEPRECATED_SINCE(6, 4) + QT_DEPRECATED_VERSION_X_6_4("Use QQmlTriviallyDestructibleDebuggingEnabler instead " + "or just call QQmlDebuggingEnabler::enableDebugging().") QQmlDebuggingEnabler(bool printWarning = true); +#endif static QStringList debuggerServices(); static QStringList inspectorServices(); @@ -73,12 +79,23 @@ struct Q_QML_EXPORT QQmlDebuggingEnabler const QVariantHash &configuration = QVariantHash()); }; +// Unnamed namespace to signal the compiler that we +// indeed want each TU to have its own QQmlDebuggingEnabler. +namespace { +struct QQmlTriviallyDestructibleDebuggingEnabler { + QQmlTriviallyDestructibleDebuggingEnabler(bool printWarning = true) + { + static_assert(std::is_trivially_destructible_v<QQmlTriviallyDestructibleDebuggingEnabler>); + QQmlDebuggingEnabler::enableDebugging(printWarning); + } +}; // Execute code in constructor before first QQmlEngine is instantiated #if defined(QT_QML_DEBUG_NO_WARNING) -static QQmlDebuggingEnabler qQmlEnableDebuggingHelper(false); +static QQmlTriviallyDestructibleDebuggingEnabler qQmlEnableDebuggingHelper(false); #elif defined(QT_QML_DEBUG) -static QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true); +static QQmlTriviallyDestructibleDebuggingEnabler qQmlEnableDebuggingHelper(true); #endif +} // unnamed namespace #endif |