QDBusInterface Class
La clase QDBusInterface es un proxy para interfaces de objetos remotos. Más...
| Cabecera: | #include <QDBusInterface> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS DBus)target_link_libraries(mytarget PRIVATE Qt6::DBus) |
| qmake: | QT += dbus |
| Hereda: | QDBusAbstractInterface |
Funciones Públicas
| QDBusInterface(const QString &service, const QString &path, const QString &interface = QString(), const QDBusConnection &connection = QDBusConnection::sessionBus(), QObject *parent = nullptr) | |
| virtual | ~QDBusInterface() |
Descripción Detallada
QDBusInterface es una clase accesoria genérica que se utiliza para realizar llamadas a objetos remotos, conectarse a señales exportadas por objetos remotos y obtener/establecer el valor de propiedades remotas. Esta clase es útil para el acceso dinámico a objetos remotos: es decir, cuando no se dispone de un código generado que represente la interfaz remota.
Las llamadas suelen realizarse mediante la función call(), que construye el mensaje, lo envía por el bus, espera la respuesta y descodifica la respuesta. Las señales se conectan mediante la función normal QObject::connect(). Por último, se accede a las propiedades mediante las funciones QObject::property() y QObject::setProperty().
El siguiente fragmento de código demuestra cómo realizar una operación matemática de "2 + 2" en una aplicación remota llamada com.example.Calculator, a la que se accede a través del bus de sesión.
QDBusInterface remoteApp( "com.example.Calculator", "/Calculator/Operations", "org.mathematics.RPNCalculator" ); remoteApp.call( "PushOperand", 2 ); remoteApp.call( "PushOperand", 2 ); remoteApp.call( "ExecuteOperation", "+" ); QDBusReply<int> reply = remoteApp.call( "PopOperand" ); if ( reply.isValid() ) printf( "%d", reply.value() ); // prints 4
Véase también Qt D-Bus Compilador XML (qdbusxml2cpp).
Documentación de funciones miembro
QDBusInterface::QDBusInterface(const QString &service, const QString &path, const QString &interface = QString(), const QDBusConnection &connection = QDBusConnection::sessionBus(), QObject *parent = nullptr)
Crea un objeto QDBusInterface dinámico asociado con la interfaz interface en el objeto en la ruta path en el servicio service, utilizando el connection dado. Si interface es una cadena vacía, el objeto creado hará referencia a la fusión de todas las interfaces encontradas mediante la introspección de ese objeto. En caso contrario, si interface no está vacío, el objeto QDBusInterface se almacenará en caché para acelerar futuras creaciones de la misma interfaz.
parent se pasa al constructor de la clase base.
Si el servicio remoto service no está presente o si se produce un error al intentar obtener la descripción de la interfaz remota interface, el objeto creado no será válido (véase isValid()).
[virtual noexcept] QDBusInterface::~QDBusInterface()
Destruye la interfaz del objeto y libera cualquier recurso utilizado.
© 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.