如何使用 CMake 项目调试 QML

Man*_*d3r 3 c++ debugging qt cmake qml

我已经设置了标志 -DQT_QML_DEBUG 并在“构建并运行 > 运行 > 调试器设置”(我的翻译)中选中了“启用 QML”,但我仍然无法使用调试器。指令指针根本不显示,文本视图不跟随指令指针。另外,我在启动时收到此警告:

Warning: "QML Debugger: Invalid argument 'services:DebugMessages' detected. Ignoring the same."
Warning: "QML Debugger: Invalid argument 'QmlDebugger' detected. Ignoring the same."
Warning: "QML Debugger: Invalid argument 'V8Debugger' detected. Ignoring the same."
Warning: "QML Debugger: Invalid argument 'QmlInspector' detected. Ignoring the same."
QML Debugger: Waiting for connection on port 39750...
Run Code Online (Sandbox Code Playgroud)

编辑:环境是 archlinux,因此是最新版本。

Mat*_*uhn 5

需要禁用编译 qml 文件以进行调试。

FIND_PACKAGE(Qt5QuickCompiler QUIET)
IF(Qt5QuickCompiler_FOUND AND NOT CMAKE_BUILD_TYPE MATCHES Debug AND NOT CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
  QTQUICK_COMPILER_ADD_RESOURCES(RESOURCES qml.qrc)
ELSE()
  SET(RESOURCES qml.qrc)
ENDIF()

ADD_EXECUTABLE(my_target_name
  ...
  ${RESOURCES}
)
Run Code Online (Sandbox Code Playgroud)

并且目标需要建立QT_QML_DEBUG

TARGET_COMPILE_DEFINITIONS(my_target_name
  PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
Run Code Online (Sandbox Code Playgroud)

这应该可以在不玩的情况下工作QQmlDebuggingEnabler