QQmlDebuggingEnabler Struct
The QQmlDebuggingEnabler class provides methods to enable debugging or profiling. More...
| Header: | #include <QQmlDebuggingEnabler> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml)target_link_libraries(mytarget PRIVATE Qt6::Qml) |
| qmake: | QT += qml |
Public Types
| enum | StartMode { DoNotWaitForClient, WaitForClient } |
Static Public Members
| bool | connectToLocalDebugger(const QString &socketFileName, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient) |
| QStringList | debuggerServices() |
| void | enableDebugging(bool printWarning) |
| QStringList | inspectorServices() |
| QStringList | nativeDebuggerServices() |
| QStringList | profilerServices() |
| void | setServices(const QStringList &services) |
| bool | startDebugConnector(const QString &pluginName, const QVariantHash &configuration = QVariantHash()) |
| bool | startTcpDebugServer(int port, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient, const QString &hostName = QString()) |
Detailed Description
Usually QML debugging and profiling is enabled by passing QT_ENABLE_QML_DEBUG via CMake or CONFIG+=qml_debug via qmake when building your application. At run time, the application generally parses any -qmljsdebugger command line arguments to actually start debugging or profiling.
You can instead handle these tasks manually by using the methods in this class.
Member Type Documentation
enum QQmlDebuggingEnabler::StartMode
Defines the debug connector's start behavior. You can interrupt QML engines starting while a debug client is connecting, in order to set breakpoints in or profile startup code.
| Constant | Value | Description |
|---|---|---|
QQmlDebuggingEnabler::DoNotWaitForClient | 0 | Run any QML engines as usual while the debug services are connecting. |
QQmlDebuggingEnabler::WaitForClient | 1 | If a QML engine starts while the debug services are connecting, interrupt it until they are done. |
Member Function Documentation
[static] bool QQmlDebuggingEnabler::connectToLocalDebugger(const QString &socketFileName, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient)
Enables debugging for QML engines created after calling this function. The debug connector will connect to a debugger waiting on a local socket at the given socketFileName and block the QML engine until the connection is established if mode is WaitForClient. If mode is not specified it will not block. You can only start one debug connector at a time. A debug connector may have already been started if the -qmljsdebugger= command line argument was given. This method returns true if a new debug connector was successfully started, or false otherwise.
Warning: The application connects out to whatever is listening on socketFileName and grants it control over all enabled services. Whoever can create or replace that socket, which depends on the permissions of the socket's directory, can take over the application. Use a location only the debugging user can write to. See QML debugging infrastructure.
[static] QStringList QQmlDebuggingEnabler::debuggerServices()
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 execution, evaluate expressions and similar debugging tasks. Returns List of plugin keys of default debugger services.
[static] void QQmlDebuggingEnabler::enableDebugging(bool printWarning)
Enable debugging or profiling. If printWarning is true, print the following warning to stderr:
QML debugging is enabled. Only use this in a safe environment.If printWarning is false, the warning gets suppressed. Then, nothing tells the user that debugging is enabled. Only suppress the warning if the application informs the user by other means, or if it runs in an environment where the exposure of the debug connectors is acceptable.
This method needs to be called one way or another before starting a debug connector of any kind. Otherwise the connector will refuse to start.
This method is automatically called at startup (with warnings enabled) if either:
QT_ENABLE_QML_DEBUGis passed via CMakeCONFIG+=qml_debugis passed via qmakeQT_QML_DEBUGis passed to the compiler when it builds a file that includesqqmldebug.hdirectly or indirectly. Most public headers in QtQml include it.
If QT_QML_DEBUG_NO_WARNING is passed to the compiler when it builds a file that includes qqmldebug.h directly or indirectly, the method is called with the warning suppressed instead.
Calling the method explicitly from application code has exactly the same effect as passing any of the above defines, even if none of them were passed. The absence of the defines does not guarantee the absence of a debug connector.
To make sure that an application cannot be debugged, build Qt with the qml-debug feature disabled or don't deploy the qmltooling plugins.
Warning: Never enable QML debugging in applications you deploy to production or run in an untrusted environment. The debug connectors do not authenticate or encrypt. Any peer that can reach an active connector gains control over the application. See QML debugging infrastructure for details.
See also startTcpDebugServer(), connectToLocalDebugger(), and startDebugConnector().
[static] QStringList QQmlDebuggingEnabler::inspectorServices()
Retrieves the plugin keys of the inspector services provided by default. The inspector services enable a debug client to use a visual inspector tool for Qt Quick. Returns List of plugin keys of default inspector services.
[static] QStringList QQmlDebuggingEnabler::nativeDebuggerServices()
Retrieves the plugin keys of the debug services designed to be used with a native debugger. The native debugger will communicate with these services by directly reading and writing the application's memory. Returns List of plugin keys of debug services designed to be used with a native debugger.
[static] QStringList QQmlDebuggingEnabler::profilerServices()
Retrieves the names of the profiler services provided by default. The profiler services enable a debug client to use a profiler and track the time taken by various QML and JavaScript constructs, as well as the QtQuick SceneGraph. Returns List of plugin keys of default profiler services.
[static] void QQmlDebuggingEnabler::setServices(const QStringList &services)
Restricts the services available from the debug connector. The connector will scan plugins in the "qmltooling" subdirectory of the default plugin path. If this function is not called before the debug connector is enabled, all services found that way will be available to any client. If this function is called, only the services with plugin keys given in services will be available.
Use this method to disable debugger and inspector services when profiling to get better performance and more realistic profiles. The debugger service will put any JavaScript engine it connects to into interpreted mode, disabling the JIT compiler.
Warning: A client connected to the debugger or inspector services can read and modify the state of the application, evaluate arbitrary JavaScript in it, and thereby invoke any Q_INVOKABLE method or slot, and change any property reachable from QML. Other services can leak data, replace the application's QML files, inject input events, or stall the application. By default all services found are loaded. Restricting the services reduces this exposure, but whoever can reach the debug connector can still use all services that are enabled. See QML debugging infrastructure for the exposure of each transport.
See also debuggerServices(), profilerServices(), and inspectorServices().
[static] bool QQmlDebuggingEnabler::startDebugConnector(const QString &pluginName, const QVariantHash &configuration = QVariantHash())
Enables debugging for QML engines created after calling this function. A debug connector plugin specified by pluginName will be loaded and started using the given configuration. Supported configuration entries and their semantics depend on the plugin being loaded. You can only start one debug connector at a time. A debug connector may have already been started if the -qmljsdebugger= command line argument was given. This method returns true if a new debug connector was successfully started, or false otherwise.
Warning: Whether and how clients are authenticated, and who can reach the connector, is up to the plugin. Do not assume that a connector plugin restricts access. The common ones don't. See QML debugging infrastructure.
[static] bool QQmlDebuggingEnabler::startTcpDebugServer(int port, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient, const QString &hostName = QString())
Enables debugging for QML engines created after calling this function. The debug connector will listen on port at hostName and block the QML engine until it receives a connection if mode is WaitForClient. If mode is not specified it won't block and if hostName is not specified it will listen on all available interfaces. You can only start one debug connector at a time. A debug connector may have already been started if the -qmljsdebugger= command line argument was given. This method returns true if a new debug connector was successfully started, or false otherwise.
Warning: Any host that can reach port on the interface given by hostName can connect and use all enabled services, including evaluating JavaScript in the application. Listening on all interfaces, which is the default and also the fallback if hostName is not a valid IP address, exposes the application to the whole network. Pass a loopback address such as 127.0.0.1 if the debugger runs on the same machine, and see QML debugging infrastructure.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.