- Qt 6.12
- Qt Qml
- C++ Classes
- QQmlDebuggingEnabler
- Qt 6.12.0 Reference Documentation

# 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`

- List of all members, including inherited members

## 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.

### `[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.

This method is automatically called at startup if `QT_ENABLE_QML_DEBUG` or `CONFIG+=qml_debug` is passed at build time.

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.

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.

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.

### `[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.