预览Qt Quick 应用程序
您可以在代码编辑器中预览Qt Quick 应用程序和单个QML文件。您对代码所做的更改会立即反映在预览中。
预览Qt Quick 应用程序。
预览整个应用程序
要启动并预览Qt Quick 应用程序:
- 启动应用程序:
- 在编辑器工具栏上选择“
”。 - 转到“Command Palette ”,然后选择“Qt: Preview changes to QML code live in your application ”。
- 在编辑器工具栏上选择“
- 选择应用程序可执行文件作为启动目标。
如果构建目录位于工作区之外,请选择“Qt: Open Qt Extension settings ” > Qt Qml Configuration 在“Preview: Additional Build Dirs ”中进行设置。这会告知 Qt Extension for VS Code 在 QML 预览期间应从何处查找 QRC 文件。
若要在从命令面板启动应用程序时向其传递命令行参数,请在“Qt: Open Qt Extension settings ” > Qt Qml Configuration >Preview: Args 中进行设置。
预览单个文件
要预览单个 QML 文件:
- 在编辑器工具栏上选择“
”。 - 转到“Command Palette ”,然后选择“Qt: Preview current QML file live ”。
连接到正在运行的应用程序以进行实时预览
要连接到正在运行的Qt Quick 应用程序以进行实时预览:
- 在Terminal 中,使用以下参数启动应用程序:
<your_executable_path> -qmljsdebugger=host:<IP_address>,port:<port_number>,block,services:QmlPreview,DebugTranslation
其中IP_address是应用程序运行的主机的 IP 地址,port_number是调试端口。
- 访问Command Palette ,然后选择“Qt: Attach to a running QML application for live preview ”。
- 输入应用程序运行的 IP 地址。
- 输入应用程序运行的端口号。
停止预览
要停止预览Qt Quick 应用程序或 QML 文件:
- 关闭预览窗口。
- 在编辑器工具栏上选择“
”。 - 转到“Command Palette ”,然后选择“Qt: Stop QML Preview ”。
重新加载预览窗口
要重新加载预览窗口,请转到“Command Palette ”,然后选择“Qt: Reload QML Preview ”。
另请参阅 Qt 设置。
© 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.