配置Qt Quick 应用程序
您可以使用集成到Qt Creator 中的QML Profiler 来配置从 Visual Studio 运行的Qt Quick 应用程序。通过QML Profiler ,您可以找到应用程序中典型性能问题的原因,如速度慢、用户界面反应迟钝、卡顿等。
造成此类性能问题的一个典型原因是在太少的帧中执行了太多的 JavaScript。在图形用户界面线程继续运行之前,所有 JavaScript 必须返回,如果图形用户界面线程尚未准备就绪,帧就会被延迟或丢弃。另一个典型原因是创建或更新不可见项,这需要在 GUI 线程中花费时间。
要对Qt Quick 应用程序进行剖析:
- 在 Visual Studio 中,打开Qt Quick 应用程序项目。
- 在Solution Explorer 中,右键单击该项目,然后在上下文菜单中选择Properties 。
- 选择Configuration Properties >Qt Project Settings 。
- 在Enable QML Debugging 中,选择Yes 。

- 选择Debugging 。
- 在Command arguments 中,输入:
-qmljsdebugger=port:<number>,block
注意: 命令参数与Environment 中默认设置的参数相冲突,因此在删除这些参数之前,调试将无法进行。
- 选择OK 。
- 转到Build ,然后选择Build Solution 以构建应用程序。
- 转到Debug ,然后选择Start without Debugging (或按Ctrl+F5)运行应用程序。
- 在Qt Creator 中,转到Analyze ,然后选择 QML Profiler (Attach to Waiting Application).
Qt Creator 启动 QML Profiler 对话框" src="images/qtcreator-start-qml-profiler.webp" title="Qt Creator 启动 QML Profiler 对话框"/>
- 在Port 中,设置与命令参数中相同的端口号。
- 选择OK 开始剖析。
- 如果剖析没有立即在 QML Profiler中,选择Enable Profiling 开始收集数据。
另请参阅 Enable QML debugging(启用 QML调试)、Qt Creator:Profile QML applications(剖析 QML 应用程序)和Qt Creator: Profiling QML applications(剖析 QML 应用程序)。
© 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.