Back to Blog home

QML Debugging in Visual Studio

Published on Monday October 08, 2018 by Miguel Costa in Labs Dev Loop Qt Visual Studio Windows integration | Comments

The next release of the Qt Visual Studio Tools, v2.3.0, will allow debugging of QML applications in Visual Studio. It will be possible to set breakpoints in QML files and step through the execution of QML code. While in break mode, it will be possible to watch variables and change their values, as well as evaluate arbitrary expressions. The QML debug session will run concurrently to the C++ debug session, so it will be possible to set breakpoints and watch variables in both C++ and QML during the same debug run of the application.

This new debugging feature of the Qt VS Tools integrates with the QML debugging infrastructure, a part of the Qt QML module which provides services for debugging, inspecting, and profiling applications via a TCP port. To extend the Visual Studio debugger with features of the QML debugging infrastructure, a Visual Studio QML debug engine is provided. This debug engine consists, for the most part, of implementations of interfaces from the Active Debugging 7 (AD7) extensibility framework for the Visual Studio debugger.

If a Qt project contains any QML resource files, starting a debug session (e.g. by pressing F5), besides launching the native application, now also connects to the QML debugging infrastructure of that application. This can be seen in the Processes window of the Visual Studio debugger: two processes are listed, a native process that corresponds to the actual physical process created for the C++ debugging session, and a QML process, which does not correspond to any physical process that is running on the machine, but rather represents the connection to the QML debugging runtime within the native process.

qml_vs_debug_processes_1

Since both a native process and a QML process are present, it is possible to request breakpoints both in C++ or QML code. The Visual Studio debugger will forward requests to the appropriate debug engine. As usual, a filled circular breakpoint marker in QML code indicates a valid breakpoint; this means that a breakpoint request for that file position has been sent to, and confirmed by the QML runtime.

qml_vs_debug_breakpoints_1

When a breakpoint is hit, Visual Studio will show the current state of the call stack. Unlike other scenarios of debugging applications that use different languages (e.g. .NET + Native debugging), the QML debug engine does not provide true mixed mode debugging. It runs concurrently with the native debug engine and, from the point of view of the Visual Studio debugger, it is not related to the native process. This means that, even though it is possible to debug both C++ and QML in the same debugging session, the stack that is shown when a QML breakpoint is hit will only include QML function calls -- the C++ context of those calls will not be available.

qml_vs_debug_callstack_1

As in the case of native debugging, while in break mode, it is possible to view and modify the values of local variables, in the context of the currently active call stack frame, as well as create watches for any variable or expression. The Immediate window is also available for evaluation of any expression in the context of the current stack frame.

qml_vs_debug_watches_1

Moving the mouse over a QML expression pops up an instant watch window (or "DataTip"). The value of that expression in the current context is displayed and can also be modified.

qml_vs_debug_datatip_1

QML debugging is enabled by default for any Qt QML application. It is possible to disable QML debugging, and revert to native-only debugging, by opening the Qt project settings dialog and setting the "QML Debug" option to "Disable". In this dialog, it is also possible to change the port that is used by the QML debugging runtime.

qml_vs_debug_options_2

As mentioned, the QML debugging feature of the Qt VS Tools will be available in the next version, scheduled for release in the Visual Studio Marketplace later this year. A preview version will shortly be available for download on the Qt website; we'll post a quick update here when it is available.

Subscribe to Our Blog

Stay up to date with the latest marketing, sales and service tips and news.

The blog comment system has been migrated to a new platform. If you face any issues, please let us know via feedback@qt.io.