2011-09-27 11:52:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2021-03-29 16:10:36 +02:00
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
2016-01-15 14:51:16 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-09-27 11:52:34 +02:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** This file is part of the Qt Creator documentation.
|
2011-09-27 11:52:34 +02:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-09-27 11:52:34 +02:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** GNU Free Documentation License Usage
|
2011-09-27 11:52:34 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Free
|
|
|
|
|
** Documentation License version 1.3 as published by the Free Software
|
2016-01-15 14:51:16 +01:00
|
|
|
** Foundation and appearing in the file included in the packaging of
|
|
|
|
|
** this file. Please review the following information to ensure
|
|
|
|
|
** the GNU Free Documentation License version 1.3 requirements
|
|
|
|
|
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
|
2011-09-27 11:52:34 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
// NOTE: the sections are not ordered by their logical order to avoid
|
|
|
|
|
// reshuffling the file each time the index order changes (i.e., often).
|
|
|
|
|
// Run the fixnavi.pl script to adjust the links to the index order.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\page creator-debugging-qml.html
|
2018-08-10 16:15:05 +02:00
|
|
|
\if defined(qtdesignstudio)
|
2018-08-17 14:18:57 +02:00
|
|
|
\previouspage studio-debugging.html
|
2018-08-10 16:15:05 +02:00
|
|
|
\nextpage creator-qml-debugging-example.html
|
|
|
|
|
\else
|
|
|
|
|
\previouspage creator-debugging-helpers.html
|
2012-04-16 15:09:32 +02:00
|
|
|
\nextpage creator-debugging-example.html
|
2018-08-10 16:15:05 +02:00
|
|
|
\endif
|
2011-09-27 11:52:34 +02:00
|
|
|
|
|
|
|
|
\title Debugging Qt Quick Projects
|
|
|
|
|
|
2018-08-20 13:33:07 +02:00
|
|
|
\if defined(qtcreator)
|
2017-08-11 10:36:43 +02:00
|
|
|
\note You need Qt 5.0 or later to debug Qt Quick projects.
|
2018-08-20 13:33:07 +02:00
|
|
|
\endif
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2012-01-09 11:04:29 +01:00
|
|
|
For an example of how to debug Qt Quick Projects, see
|
|
|
|
|
\l{Debugging a Qt Quick Example Application}.
|
|
|
|
|
|
2022-02-28 13:44:07 +02:00
|
|
|
\if defined(qtdesignstudio)
|
|
|
|
|
\note In this section, you are using advanced menu items. These are not
|
|
|
|
|
visible by default. To toggle the visibility of advanced menu items, see
|
|
|
|
|
\l{Customizing the Menu}.
|
|
|
|
|
\endif
|
|
|
|
|
|
2011-09-27 11:52:34 +02:00
|
|
|
\section1 Setting Up QML Debugging
|
|
|
|
|
|
2018-08-20 13:33:07 +02:00
|
|
|
\if defined(qtcreator)
|
2011-09-27 11:52:34 +02:00
|
|
|
The process of setting up debugging for Qt Quick projects depends on the
|
2012-01-09 11:04:29 +01:00
|
|
|
\l{Creating Qt Quick Projects}{type of the project}: Qt Quick UI or Qt Quick
|
|
|
|
|
Application, and the Qt version used.
|
2018-08-20 13:33:07 +02:00
|
|
|
\endif
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
To debug Qt Quick UI projects, select the \uicontrol {Enable QML} check box in the
|
|
|
|
|
\uicontrol {Debugger Settings} in \uicontrol Projects mode \uicontrol {Run Settings}.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2018-08-20 13:33:07 +02:00
|
|
|
\if defined(qtcreator)
|
2011-09-27 11:52:34 +02:00
|
|
|
To debug Qt Quick Applications:
|
|
|
|
|
|
|
|
|
|
\list 1
|
|
|
|
|
|
2021-03-29 16:10:36 +02:00
|
|
|
\li If you use qmake as the build system, make sure that
|
|
|
|
|
debugging is enabled in the \uicontrol {Build Settings},
|
|
|
|
|
\uicontrol {QML debugging and profiling} field, either
|
|
|
|
|
explicitly for the project or globally by default.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2020-03-04 18:00:48 +01:00
|
|
|
\image qtcreator-projectpane.png "qmake general build settings pane"
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2017-08-11 10:36:43 +02:00
|
|
|
\note Debugging requires opening a socket at a TCP port,
|
2011-09-27 11:52:34 +02:00
|
|
|
which presents a security risk. Anyone on the Internet could connect
|
|
|
|
|
to the application that you are debugging and execute any JavaScript
|
|
|
|
|
functions. Therefore, you must make sure that the port is properly
|
|
|
|
|
protected by a firewall.
|
|
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
\li In the \uicontrol {Run Settings}, \uicontrol {Debugger Settings} section, select
|
|
|
|
|
the \uicontrol {Enable QML} check box to enable
|
2011-09-27 11:52:34 +02:00
|
|
|
QML debugging.
|
|
|
|
|
|
2020-04-02 11:46:41 +02:00
|
|
|
\li Select \uicontrol Build > \uicontrol {Rebuild Project} to clean and
|
|
|
|
|
rebuild the project.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2017-08-17 17:02:56 +02:00
|
|
|
\li To debug applications on \l{glossary-device}{devices}, check that
|
|
|
|
|
Qt 5.0, or later, libraries are installed on the device and
|
2012-09-14 12:44:57 +02:00
|
|
|
\l{Running on Multiple Platforms}{select the corresponding kit for the device}
|
2012-01-09 11:04:29 +01:00
|
|
|
before you start debugging.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2012-01-09 11:04:29 +01:00
|
|
|
\endlist
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2020-02-11 14:52:52 +01:00
|
|
|
\note The \c qmltooling plugins that are required for debugging are
|
|
|
|
|
automatically installed during \QC and Qt installation. Do not delete
|
|
|
|
|
them if you plan to debug QML applications.
|
|
|
|
|
|
2011-09-27 11:52:34 +02:00
|
|
|
\section1 Mixed C++/QML Debugging
|
|
|
|
|
|
|
|
|
|
To debug both the C++ and QML parts of your application at the same time,
|
2014-12-11 15:43:19 +01:00
|
|
|
select the \uicontrol {Enable C++} and \uicontrol {Enable QML} checkboxes for both
|
|
|
|
|
languages in the \uicontrol {Debugger Settings} section in the project
|
|
|
|
|
\uicontrol{Run Settings}.
|
2018-08-20 13:33:07 +02:00
|
|
|
\endif
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2012-01-09 11:04:29 +01:00
|
|
|
\image qtquick-debugging-settings.png
|
|
|
|
|
|
2011-09-27 11:52:34 +02:00
|
|
|
\section1 Starting QML Debugging
|
|
|
|
|
|
2019-03-22 12:01:49 +01:00
|
|
|
To start the application, choose \uicontrol Debug > \uicontrol {Start Debugging}
|
|
|
|
|
> \uicontrol {Start Debugging of Startup Project} or press \key F5. Once the
|
|
|
|
|
application starts running, it behaves and performs as usual. You can then
|
|
|
|
|
perform the following tasks:
|
2011-09-27 11:52:34 +02:00
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Debug JavaScript functions
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Execute JavaScript expressions to get information about the state of
|
2012-01-09 11:04:29 +01:00
|
|
|
the application
|
|
|
|
|
|
2017-08-11 10:36:43 +02:00
|
|
|
\li Inspect QML properties and JavaScript variables and change them
|
|
|
|
|
temporarily at runtime
|
2012-01-09 11:04:29 +01:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
To debug already running applications:
|
|
|
|
|
|
|
|
|
|
\list 1
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2018-08-20 13:33:07 +02:00
|
|
|
\if defined(qtcreator)
|
2013-08-08 11:30:52 +02:00
|
|
|
\li Build the application by using the appropriate configuration
|
|
|
|
|
parameters (if you build the application with \QC, it automatically
|
|
|
|
|
uses the correct configuration):
|
2021-12-06 13:52:16 +01:00
|
|
|
\list
|
|
|
|
|
\li When using CMake, the
|
|
|
|
|
\l{CMake: target_compile_definitions command}
|
|
|
|
|
{target_compile_definitions} command is defined
|
|
|
|
|
in the CMakeLists.txt file:
|
|
|
|
|
\c {target_compile_definitions(myapp PRIVATE QT_QML_DEBUG)}
|
|
|
|
|
|
|
|
|
|
Where \e myapp is the application to debug.
|
|
|
|
|
\li When using qmake, the following value is defined for the
|
|
|
|
|
\l CONFIG property in the .pro file:
|
|
|
|
|
\c {CONFIG += qml_debug}
|
|
|
|
|
\endlist
|
2018-08-20 13:33:07 +02:00
|
|
|
\endif
|
2013-08-08 11:30:52 +02:00
|
|
|
|
|
|
|
|
\li Start the application with the following arguments:
|
|
|
|
|
|
|
|
|
|
\c {qmljsdebugger=port:<port>[,host:<ip address>][,block]}
|
|
|
|
|
|
|
|
|
|
Where \c port (mandatory) specifies the debugging port,
|
|
|
|
|
\c {ip address} (optional) specifies the IP address of the host
|
|
|
|
|
where the application is running, and \c block (optional) prevents
|
|
|
|
|
the application from running until the debug client connects to the
|
|
|
|
|
server. This enables debugging from the start.
|
2012-01-09 11:04:29 +01:00
|
|
|
|
2020-04-02 11:46:41 +02:00
|
|
|
\li Select \uicontrol Debug > \uicontrol {Start Debugging} >
|
|
|
|
|
\uicontrol {Attach to QML Port}.
|
2012-01-09 11:04:29 +01:00
|
|
|
|
2013-08-08 11:30:52 +02:00
|
|
|
Choose the kit configured for the device where the application to
|
|
|
|
|
be debugged is running. The port number to use is displayed in the
|
|
|
|
|
standard output when the application starts.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
\section1 Debugging JavaScript Functions
|
|
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
You can use the \QC \uicontrol Debug mode to inspect the state of your
|
2012-01-09 11:04:29 +01:00
|
|
|
application while debugging. You can interact with the debugger by:
|
2011-09-27 11:52:34 +02:00
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li \l{Setting Breakpoints}{Setting breakpoints}
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li \l{Viewing Call Stack Trace}{Viewing call stack trace}
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2017-10-26 16:32:48 +02:00
|
|
|
\li \l{Local Variables and Function Parameters}
|
|
|
|
|
{Viewing local variables and function parameters}
|
|
|
|
|
|
2019-07-23 11:57:05 +02:00
|
|
|
\li \l{Evaluating Expressions}
|
2011-09-27 11:52:34 +02:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
2018-08-17 14:18:57 +02:00
|
|
|
\if defined(qtdesignstudio)
|
|
|
|
|
\include creator-debugger-common.qdocinc debugger-breakpoints
|
|
|
|
|
\include creator-debugger-common.qdocinc debugger-call-stack-trace
|
|
|
|
|
\include creator-debugger-common.qdocinc debugger-locals
|
2019-07-23 11:57:05 +02:00
|
|
|
\include creator-debugger-common.qdocinc debugger-expressions
|
2018-08-17 14:18:57 +02:00
|
|
|
\endif
|
|
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
\section1 Inspecting Items
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2017-10-26 16:32:48 +02:00
|
|
|
While the application is running, you can use the \uicontrol {Locals}
|
2019-07-23 11:57:05 +02:00
|
|
|
view to explore the QML item structure.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
\image qml-observer-view.png "QML item tree"
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2016-04-28 14:57:25 +02:00
|
|
|
To keep the application visible while you interact with the debugger, select
|
|
|
|
|
\uicontrol Debug > \uicontrol {Show Application on Top}.
|
2012-01-09 11:04:29 +01:00
|
|
|
|
2019-07-23 11:57:05 +02:00
|
|
|
You can view a QML item in the \uicontrol {Locals} view in the following
|
|
|
|
|
ways:
|
2012-01-09 11:04:29 +01:00
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
\li Expand the item in the object tree.
|
2012-09-27 15:13:25 +02:00
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
\li Select the item in the code editor.
|
2012-01-09 11:04:29 +01:00
|
|
|
|
2016-04-28 14:57:25 +02:00
|
|
|
\li Select \uicontrol Debug > \uicontrol Select to activate selection
|
|
|
|
|
mode and then click an item in the running application.
|
2012-01-09 11:04:29 +01:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
To change property values temporarily, without editing the source,
|
|
|
|
|
double-click them and enter the new values. You can view the results in the
|
|
|
|
|
running application.
|
|
|
|
|
|
2012-09-27 15:13:25 +02:00
|
|
|
\section1 Inspecting User Interfaces
|
2012-01-09 11:04:29 +01:00
|
|
|
|
2012-09-27 15:13:25 +02:00
|
|
|
When you debug complex applications, you can jump to the position in code
|
2017-08-11 10:36:43 +02:00
|
|
|
where an item is defined.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2016-04-28 14:57:25 +02:00
|
|
|
In the selection mode, you can click items in the running
|
2011-09-27 11:52:34 +02:00
|
|
|
application to jump to their definitions in the code. The properties of the
|
2017-10-26 16:32:48 +02:00
|
|
|
selected item are displayed in the \uicontrol {Locals} view.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2018-08-20 13:33:07 +02:00
|
|
|
\if defined(qtcreator)
|
2016-04-18 11:47:42 +02:00
|
|
|
The \uicontrol Select tool will be enabled either if your application is
|
|
|
|
|
using Qt 5.7 or later, or if your application is using an earlier version
|
|
|
|
|
of Qt and is based on the \c QQuickView class.
|
2018-08-20 13:33:07 +02:00
|
|
|
\endif
|
2016-04-18 11:47:42 +02:00
|
|
|
|
2014-12-08 14:46:32 +01:00
|
|
|
You can also view the item hierarchy in the running application:
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2017-08-11 10:36:43 +02:00
|
|
|
Double-click an item in the running application to cycle through the item
|
|
|
|
|
stack at the cursor position.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2016-04-28 14:57:25 +02:00
|
|
|
To switch out of the selection mode, toggle the \uicontrol Select menu item.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2016-04-28 14:57:25 +02:00
|
|
|
To move the application running in \QQV to the front, select
|
|
|
|
|
\uicontrol Debug > \uicontrol {Show Application on Top}.
|
2011-09-27 11:52:34 +02:00
|
|
|
|
2018-08-20 13:33:07 +02:00
|
|
|
\section1 Executing JavaScript Expressions
|
|
|
|
|
|
|
|
|
|
When the application is interrupted by a breakpoint, you can use the
|
2019-03-22 10:07:20 +01:00
|
|
|
\uicontrol {QML Debugger Console} to execute JavaScript expressions in the
|
2022-03-04 18:24:58 +01:00
|
|
|
current context. To open it, choose \uicontrol View > \uicontrol Output >
|
|
|
|
|
\uicontrol {QML Debugger Console}.
|
2018-08-20 13:33:07 +02:00
|
|
|
|
2019-03-22 10:07:20 +01:00
|
|
|
\image qml-script-console.png "QML Debugger Console"
|
2018-08-20 13:33:07 +02:00
|
|
|
|
|
|
|
|
You can change property values temporarily, without editing the source, and
|
|
|
|
|
view the results in the running application. You can change the property
|
2021-10-05 15:50:41 +02:00
|
|
|
values permanently in
|
|
|
|
|
\if defined(qtcreator)
|
|
|
|
|
code.
|
|
|
|
|
\else
|
|
|
|
|
the \l Properties view.
|
|
|
|
|
\endif
|
2018-08-20 13:33:07 +02:00
|
|
|
|
|
|
|
|
\section1 Applying QML Changes at Runtime
|
|
|
|
|
|
2019-03-22 10:07:20 +01:00
|
|
|
When you change property values in the \uicontrol {QML Debugger Console} or
|
|
|
|
|
in the \uicontrol Locals or \uicontrol Expression view, they are immediately
|
2018-08-20 13:33:07 +02:00
|
|
|
updated in the running application, but not in the source code.
|
2011-09-27 11:52:34 +02:00
|
|
|
*/
|