QQmlDebuggingEnabler Struct
QQmlDebuggingEnabler 类提供了启用调试或剖析的方法。更多
| 头文件: | #include <QQmlDebuggingEnabler> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml)target_link_libraries(mytarget PRIVATE Qt6::Qml) |
| qmake: | QT += qml |
公共类型
| enum | StartMode { DoNotWaitForClient, WaitForClient } |
静态公共成员
| bool | connectToLocalDebugger(const QString &socketFileName, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient) |
| QStringList | debuggerServices() |
| void | enableDebugging(bool printWarning) |
| QStringList | inspectorServices() |
| QStringList | nativeDebuggerServices() |
| QStringList | profilerServices() |
| void | setServices(const QStringList &services) |
| bool | startDebugConnector(const QString &pluginName, const QVariantHash &configuration = QVariantHash()) |
| bool | startTcpDebugServer(int port, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient, const QString &hostName = QString()) |
详细说明
通常 QML 调试和剖析是在构建应用程序时通过 CMake 传递QT_ENABLE_QML_DEBUG 或通过 qmake 传递CONFIG+=qml_debug 来启用的。运行时,应用程序通常会解析-qmljsdebugger 命令行参数,以实际启动调试或剖析。
您可以使用该类中的方法手动处理这些任务。
成员类型文档
enum QQmlDebuggingEnabler::StartMode
定义调试连接器的启动行为。您可以在调试客户端连接时中断 QML 引擎的启动,以便在启动代码中设置断点或剖析启动代码。
| 常数 | 值 | 说明 |
|---|---|---|
QQmlDebuggingEnabler::DoNotWaitForClient | 0 | 当调试服务正在连接时,照常运行任何 QML 引擎。 |
QQmlDebuggingEnabler::WaitForClient | 1 | 如果 QML 引擎在调试服务连接时启动,则中断它直到调试服务完成。 |
成员函数文档
[static] bool QQmlDebuggingEnabler::connectToLocalDebugger(const QString &socketFileName, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient)
启用调试调用此函数后创建的 QML 引擎。socketFileName 如果mode 是WaitForClient ,调试连接器将连接到本地套接字上等待的调试器,并阻塞 QML 引擎,直到连接建立。如果mode 未指定,则不会阻塞。一次只能启动一个调试连接器。如果给定了 -qmljsdebugger= 命令行参数,调试连接器可能已经启动。如果成功启动了新的调试连接器,本方法将返回true ,否则返回false 。
[static] QStringList QQmlDebuggingEnabler::debuggerServices()
读取默认提供的调试器服务的插件密钥。调试器服务可使调试客户端使用 Qml/JavaScript 调试器,以设置断点、暂停执行、评估表达式及类似调试任务。返回 默认调试器服务的插件键列表。
[static] void QQmlDebuggingEnabler::enableDebugging(bool printWarning)
启用调试或剖析。如果printWarning 是true ,则向 stderr 打印以下警告:
QML debugging is enabled. Only use this in a safe environment.
如果在构建时传递了QT_ENABLE_QML_DEBUG 或CONFIG+=qml_debug ,则在启动时会自动调用此方法。
在启动任何类型的调试连接器之前,都需要以某种方式调用此方法。否则,连接器将拒绝启动。
另请参阅 startTcpDebugServer()、connectToLocalDebugger() 和startDebugConnector()。
[static] QStringList QQmlDebuggingEnabler::inspectorServices()
读取默认提供的检查器服务的插件密钥。检查器服务可使调试客户端使用可视化检查器工具Qt Quick 。返回 默认检查器服务的插件密钥列表。
[static] QStringList QQmlDebuggingEnabler::nativeDebuggerServices()
读取与本地调试器一起使用的调试服务的插件密钥。本机调试器将通过直接读写应用程序内存与这些服务通信。返回与本地调试器一起使用的调试服务的插件密钥列表。
[static] QStringList QQmlDebuggingEnabler::profilerServices()
读取默认提供的剖析器服务名称。剖析器服务可让调试客户端使用剖析器,跟踪各种 QML 和 JavaScript 构造以及QtQuick SceneGraph 所耗费的时间。返回 默认剖析器服务的插件键列表。
[static] void QQmlDebuggingEnabler::setServices(const QStringList &services)
限制调试连接器提供的服务。连接器将扫描默认插件路径中 "qmltooling "子目录下的插件。如果在启用调试连接器之前没有调用此函数,那么通过这种方式找到的所有服务都将提供给任何客户端。如果调用此函数,则只有在services 中给出插件键的服务才可用。
使用此方法可在剖析时禁用调试器和检查器服务,以获得更好的性能和更真实的剖析。调试器服务会将其连接的任何 JavaScript 引擎设置为解释模式,禁用 JIT 编译器。
另请参阅 debuggerServices()、profilerServices() 和inspectorServices()。
[static] bool QQmlDebuggingEnabler::startDebugConnector(const QString &pluginName, const QVariantHash &configuration = QVariantHash())
启用调试调用此函数后创建的 QML 引擎。pluginName 指定的调试连接器插件将被加载,并使用给定的configuration 启动。支持的配置项及其语义取决于加载的插件。一次只能启动一个调试连接器。如果给定了 -qmljsdebugger= 命令行参数,调试连接器可能已经启动。如果成功启动了新的调试连接器,本方法返回true ,否则返回false 。
[static] bool QQmlDebuggingEnabler::startTcpDebugServer(int port, QQmlDebuggingEnabler::StartMode mode = DoNotWaitForClient, const QString &hostName = QString())
启用调试调用此函数后创建的 QML 引擎。调试连接器将监听port hostName ,如果mode 是WaitForClient ,则会阻塞 QML 引擎,直到收到连接。如果mode 未指定,则不会阻塞;如果hostName 未指定,则会监听所有可用接口。一次只能启动一个调试连接器。如果给定了 -qmljsdebugger= 命令行参数,调试连接器可能已经启动。如果成功启动了新的调试连接器,本方法将返回true ,否则返回false 。
© 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.