在此页面

在 Linux 上调试

设置在 Linux 上交叉编译的 Qt VS Tools,以调试在 Linux 设备上运行的应用程序。首先使用gdbserver 启动应用程序,然后配置 GDB 以连接到设备并启动远程调试会话。

调试 Linux 设备上运行的应用程序

要做到这一点,WSL 中安装的 GDB 必须支持目标设备架构。实现这一目标的简单方法是安装gdb-multiarch 。为确保 Visual Studio 使用正确的调试器,请创建一个符号链接,从gdb 链接到gdb-multiarch 。

设置远程调试

要在 Visual Studio 中设置远程调试会话,必须向 GDB 传递附加命令:

  1. 在Solution Explorer 中选择一个项目。
  2. 转到Project >Properties >Configuration Properties >Debugging 。

    调试属性

  3. 在Debugger to launch 中,选择GDB Debugger 。
  4. 在Additional Debugger Commands 中,添加以下命令:
    target extended-remote <IP_address>:<port>
    set remote exec-file <path_to_executable>

设置环境变量

在启动远程调试会话之前:

  1. 设置所需的环境变量:
    • LD_LIBRARY_PATH指定安装 Qt 二进制文件目录的路径。
    • QT_QPA_PLATFORM指定平台插件,如 EGLFS、LinuxFB、DirectFB 或 Wayland。
    • QT_QPA_PLATFORM_PLUGIN_PATH 指定安装平台插件的目录路径。
    • 对于EGLFS平台,QT_QPA_EGLFS_PHYSICAL_WIDTH 和QT_QPA_EGLFS_PHYSICAL_HEIGHT 指定屏幕宽度和高度(以毫米为单位)。
    • QML2_IMPORT_PATH指定安装 QML 模块的目录路径。
  2. 在设备上启动gdbserver 。

启动远程调试

按F5键启动远程调试会话。

在 Linux 设备上设置调试

在 Linux 设备上调试Qt Quick 应用程序:

  1. 为项目启用 QML 调试。
  2. 转到Project >Properties >Configuration Properties >Debugging ,设置启动 QML 调试会话的程序参数。
  3. 在Debugger to launch 中,选择GDB Debugger 。
  4. 在Additional Debugger Commands 中,添加以下命令:
    -qmljsdebugger=port:<port>,host:<IP_address>,block

另请参阅 教程:Qt Quick 调试、交叉编译、调试应用程序、启用 QML 调试和调试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.