在 D-Bus 适配器中声明信号
只要信号的参数符合特定规则(更多信息请参阅《Qt D-Bus 类型系统》),从QDBusAbstractAdaptor 派生的类中的任何信号都会自动转发到D-Bus。实现这种转发无需编写特殊代码。
不过,信号仍需被触发。触发适配器信号最简单的方法是将其与另一个信号连接起来,这样 Qt 的信号与槽机制就会自动触发该适配器信号。如Qt D-Bus 复杂乒乓示例中所示,这可以在适配器的构造函数中实现。
还可以使用便捷函数 `QDBusAbstractAdaptor::setAutoRelaySignals()` 来建立和断开真实对象中的信号与适配器中相应信号之间的连接。该函数会检查两个类中的信号列表,并连接那些参数完全匹配的信号。
另请参阅 《使用Qt D-Bus 适配器》、《在D-Bus适配器中声明插槽》、《Qt D-Bus 类型系统》以及《QDBusAbstractAdaptor 》。
© 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.