QAndroidServiceConnection Class
封装了 Android ServiceConnection 类中最重要的方法。更多内容...
| 头文件: | #include <QtCore/private/qandroidextras_p.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS CorePrivate) target_link_libraries(mytarget PRIVATE Qt6::CorePrivate) |
| qmake: | QT += core-private |
| 自: | Qt 6.2 |
| 状态: | 技术预览 |
该类处于技术预览阶段,内容可能会有变动。
公共函数
| QAndroidServiceConnection() | |
| QAndroidServiceConnection(const QJniObject &serviceConnection) | |
| QJniObject | handle() const |
| virtual void | onServiceConnected(const QString &name, const QAndroidBinder &serviceBinder) = 0 |
| virtual void | onServiceDisconnected(const QString &name) = 0 |
详细说明
QAndroidServiceConnection 是一个便捷的抽象类,它封装了AndroidServiceConnection接口。
在执行“QtAndroidPrivate::bindService ”操作时,它非常有用。
成员函数文档
QAndroidServiceConnection::QAndroidServiceConnection()
创建一个新对象
[explicit] QAndroidServiceConnection::QAndroidServiceConnection(const QJniObject &serviceConnection)
根据现有的serviceConnection 创建一个新对象。
当您拥有自己的 Java 实现时,这非常有用。当然,此时将不再调用onServiceConnected() /onServiceDisconnected() 方法。
QJniObject QAndroidServiceConnection::handle() const
返回下划线QJniObject
[pure virtual] void QAndroidServiceConnection::onServiceConnected(const QString &name, const QAndroidBinder &serviceBinder)
当客户端成功连接到服务时,会调用此通知。name 包含服务器名称,serviceBinder 是客户端用于执行IPC操作的Binder。
警告:此 方法是在 Binder 的线程中调用的,该线程与创建此对象的线程不同。
返回下划线QJniObject
[pure virtual] void QAndroidServiceConnection::onServiceDisconnected(const QString &name)
当与服务的连接丢失时调用此方法。name 参数指定了丢失的是哪条连接。
警告:此 方法由 Binder 的线程调用,该线程与创建此对象的线程不同。
返回底线QJniObject
© 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.