Debugging QML Applications
When you develop an application with QML, there are many ways to debug possible issues that you may face. The sections below describe the debugging tools available and how to use them.
Console API
| Feature | Description |
|---|---|
| Log | Use console.log, console.debug, console.info, console.warn, or console.error to print debugging information to the console.For example: The output is generated using the qCDebug, qCWarning, or qCCritical methods in C++, with a category of See also Debugging Techniques. |
| Assert | console.assert tests that an expression is true. If not, it writes an optional message to the console and prints the stack trace.For example: |
| Timer | console.time and console.timeEnd log the time (in milliseconds) that was spent between the calls. Both take a string argument that identifies the measurement.For example: |
| Trace | console.trace prints the stack trace of the JavaScript execution at the point where it was called. This stack trace information contains the function name, file name, line number, and column number. The stack trace is limited to last 10 stack frames. |
| Count | console.count prints the current number of times a particular piece of code has run, along with a message.For example: The code sample above prints |
| Profile | console.profile turns on the QML and JavaScript profilers. Nested calls are not supported and prints a warning to the console. |
| ProfileEnd | console.profileEnd turns off the QML and JavaScript profilers. Calling this function without a previous call to console.profile prints a warning to the console. A profiling client needs to be attached before this call to receive and store the profiling data.For example: |
| Exception | console.exception prints an error message. It works like console.error but requires at least one argument and additionally prints a stack trace of the JavaScript execution at the point where it is called. |
Alternatively, a logging category can be passed as the first argument to any of these console functions. See LoggingCategory for more details.
Debugging module imports
Set the QML_IMPORT_TRACE environment variable to enable debug output from QML's import loading mechanisms.
For example, for a simple QML file like this:
import QtQuick
Rectangle { width: 100; height: 100 }If you set QML_IMPORT_TRACE=1 before running the QML Runtime Tool or your QML C++ application, you will see output similar to:
QQmlImportDatabase::addImportPath "/qt-sdk/imports"
QQmlImportDatabase::addImportPath "/qt-sdk/bin/QMLViewer.app/Contents/MacOS"
QQmlImportDatabase::addToImport 0x106237370 "." -1.-1 File as ""
QQmlImportDatabase::addToImport 0x106237370 "Qt" 4.7 Library as ""
QQmlImportDatabase::resolveType "Rectangle" = "QDeclarativeRectangle"QML debugging infrastructure
The Qt Qml module provides services for debugging, inspecting, and profiling applications via a TCP port or a local socket.
Note: The qmltooling plugins that are required for debugging and profiling QML applications on devices are automatically installed during Qt installation. They must be deployed to the devices for debugging and profiling to work.
Enabling the infrastructure
When you compile your application, you must explicitly enable the debugging infrastructure.
If you use CMake, you can pass -DCMAKE_CXX_FLAGS_INIT=-DQT_QML_DEBUG as an argument to cmake on the command line to enable it only for a specific build. You can also permanently enable it in your CMakeLists.txt file by adding the following snippet:
qt_add_executable(MyApp
...
)
target_compile_definitions(MyApp PRIVATE QT_QML_DEBUG)If you use qmake, you can add the CONFIG+=qml_debug configuration parameters to the project .pro file or pass it as argument on the command line.
If you use another build system, you need to pass the QT_QML_DEBUG define to the compiler via the build system's means.
Security considerations
Enabling the debugging infrastructure may compromise the integrity of your application and system, and therefore, you should only enable it in a controlled environment. When the infrastructure is enabled, the application usually displays the following warning:
QML debugging is enabled. Only use this in a safe environment.
The warning can be suppressed, though.
Warning: Never enable QML debugging in production builds or in applications that run in an untrusted environment. This includes enabling it at run time via QQmlDebuggingEnabler::enableDebugging(), QT_ENABLE_QML_DEBUG, QT_QML_DEBUG, QT_QML_DEBUG_NO_WARNING, or CONFIG+=qml_debug.
Any peer that can reach an active debug connector gets control of the application, with the privileges of the application's process. All services that were found are loaded unless you restrict them. The following services are shipped with Qt. The infrastructure is extensible and further services can be added by deploying them in the qmltooling plugin directory of the Qt installation.
| Service (plugin key) | What a client can do |
|---|---|
QmlDebugger | Walk the object tree, read and write properties, replace bindings and method bodies, and evaluate arbitrary JavaScript expressions in the context of any object. This can call any Q_INVOKABLE method or slot. |
V8Debugger | Set breakpoints, pause and step the JavaScript engine, inspect variables, and evaluate expressions. |
QmlInspector | Select, inspect and modify items, and change the application's UI at will. This is a way to manipulate what the user sees and does. |
QmlPreview | Upload QML and other files and make the application load them instead of its own. This replaces the application's code and resources with the client's, so it is code execution. |
DebugTranslation | Replace translations in the running application. This changes what the user sees in the respective text fields. |
EventReplay | Inject synthetic mouse and key events into the application's windows, as if the user had operated it. |
DebugMessages | Receive all log output, which can contain sensitive data, including from other libraries. |
CanvasFrameRate | Receive detailed profiling data, which discloses file names, source code locations, and what the application is doing. |
EngineControl | Hold QML engines back while they start or stop. This can be used to stall the application. |
NativeQmlDebugger | Provides state that is designed to be read and written by a native debugger directly in the application's memory. Anyone who can attach such a debugger to the process can already manipulate the application, though. |
The exposure depends on the transport. The following connector plugins are shipped with Qt. The infrastructure is extensible and further ones can be added by deploying them to Qt's qmltooling plugin directory.
| Transport | Exposure |
|---|---|
TCP (port:, QQmlDebuggingEnabler::startTcpDebugServer()) | The application listens for connections. Unless you give a host: address, it listens on all network interfaces. If the address given with host: cannot be parsed, it also listens on all network interfaces. Any machine that can reach the port can connect. If you must use the TCP transport, prefer a loopback address, and tunnel the connection (for example with SSH port forwarding) when debugging remote devices. |
Local socket (file:, QQmlDebuggingEnabler::connectToLocalDebugger()) | The application connects to a socket that a debugger has created. Only users who can create or replace that socket can take control of the application. Make sure the socket's directory is writable only by the user running the debugger. |
Native debugger (native) | The application expects a native debugger to be already attached and uses it as transport. A native debugger can already manipulate the application at will. |
Connector plugins (connector:, QQmlDebuggingEnabler::startDebugConnector()) | The plugin determines who can connect and whether any authentication takes place. This is the extension mechanism. |
Use QQmlDebuggingEnabler::setServices() or the services: argument to enable only the services you need. For example, profiling does not need the debugger and inspector services. By default, all services found in the qmltooling plugins are loaded. Restricting the services reduces what a client can do, but it does not protect against untrusted clients: all enabled services are available to every client that connects.
Disabling QML debugging for release builds
Several independent layers control whether an application can be debugged. Only the first two remove the capability:
- The
qml-debugQt feature, which is on by default. Configure Qt with-no-qml-debugto build without the debugging infrastructure. - The
qmltoolingplugins, which are installed with Qt. Deployment tools may deploy them with your application. Do not ship them in release builds. Without them, no connector or service can be loaded. - Enabling the infrastructure.
QT_QML_DEBUG,QT_QML_DEBUG_NO_WARNING,CONFIG+=qml_debugandQT_ENABLE_QML_DEBUGmerely call QQmlDebuggingEnabler::enableDebugging() from a static initializer. Any code in the application, including third-party libraries, can call it as well. An application built without the define accepts-qmljsdebuggerexactly like a debug build if this happens. - Starting a connector, via
-qmljsdebugger, or QQmlDebuggingEnabler::startTcpDebugServer(), QQmlDebuggingEnabler::connectToLocalDebugger() or QQmlDebuggingEnabler::startDebugConnector().
Enabling debugging prints a warning, unless this is suppressed by passing false to QQmlDebuggingEnabler::enableDebugging() or by defining QT_QML_DEBUG_NO_WARNING. This warning is the only notice given that debugging is enabled.
Starting applications
To enable debugging – from the start or to attach a debugger later on – start the application with the following arguments:
-qmljsdebugger=port:<port_from>[,port_to][,host:<ip address>][,block][,file:<local socket>][,services:<comma-separated list of services to enable>]
Where:
- the mandatory
port_fromspecifies either the debugging port or the start port of a range of ports whenport_tois specified - the optional
ip addressspecifies the IP address of the host where the application is running - the optional
blockprevents the application from running until the debug client connects to the server - the optional
filespecifies the local socket. - the optional
servicesspecifies the services to enable; the default is all that are found. Note that thev4 debugservice disables the JIT.
After the application has successfully started, it displays the following message:
QML Debugger: Waiting for connection on port <port_number>
or
QML Debugger: Connecting to socket at <file>
Connecting to applications
When the application is running, an IDE or a tool that implements the binary protocol can connect to the open port.
Debugging with Qt Creator
Qt Creator uses the debugging infrastructure to debug, inspect, and profile QML applications on the desktop as well as on remote devices. Qt Creator provides integrated clients for debugging JavaScript, inspecting the object tree, and profiling the activities of a QML engine. For more information, see Qt Creator: Debugging Qt Quick Projects.
Debugging with Qt Extension for Visual Studio Code
Qt Extension for Visual Studio Code provides integrated clients for debugging JavaScript and profiling QML engine activity. For more information, see Qt Extension for Visual Studio Code: Debug Qt Quick applications.
© 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.