在此页面上

教程:Qt Quick 调试

本教程说明如何使用 Qt VS Tools 调试Qt Quick 教程应用程序 QuickAddressBook。为项目启用 QML 调试后,在 QML 文件中设置断点,并逐步执行代码。在断点模式下,可观察变量并更改其值,以及评估任意表达式。

有关所有选项的更多信息,请参阅调试Qt Quick Applications。

启动前

在开始之前,您必须

设置断点

访问File >Open >File or Solution ,打开QuickAddressBook解决方案。

要查看添加新联系人的代码,请在NewAddressPopup.qml中添加一个断点,方法是单击实现onClicked 信号处理程序的行,然后选择Debug >Toggle Breakpoint (或按F9)。

设置断点

红圈表示已在该行设置了断点。

开始调试

转到Debug >Start Debugging 或按F5。

应用程序启动后,选择Add 创建新的地址簿条目。输入姓名和电子邮件地址,然后再次选择Add ,将条目添加到地址簿中。

当调试器碰到断点时,就会中断应用程序。Qt VS Tools 会将导致当前位置的嵌套函数调用显示为调用堆栈跟踪。查看并更改局部变量的值

查看变量

浏览代码

进入Debug >Step Into 或按F11键,进入堆栈中的代码。在代码编辑器中打开NewAddressPopup.qml文件,该文件位于创建新地址簿条目的函数处。

走进代码

注意变量值

Autos 和Locals 窗口会显示 Visual Studio 根据断点位置认为可能有趣的局部变量子集。要观察特定变量或表达式,请在Watch 1 视图中设置观察。

观察变量

在代码中逐步查看视图中的信息变化。

评估表达式

要在当前堆栈帧上下文中执行 JavaSript 命令,请打开Immediate Commands 窗口并键入要评估的表达式。

移除断点

要移除断点,请访问Debug >Toggle Breakpoint (或按F9)。

另请参阅 交叉编译、调试应用程序、Linux 调试和调试Qt Quick 应用程序。

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