dbus
su -
yum install qt5-qdbusviewer
qdbusviewer-qt5
.pro …. QT += core gui dbus
#ifndef RECEIVER_H #define RECEIVER_H #include <QMainWindow> namespace Ui { class Receiver; } class Receiver : public QMainWindow { Q_OBJECT Q_CLASSINFO ("D-Bus Interface", "org.example.ReceiverInterface") public: explicit Receiver(QWidget *parent = 0); ~Receiver(); public slots: Q_SCRIPTABLE void hello (QString s); Q_SCRIPTABLE QString hello2 (QString s); private: Ui::Receiver *ui; }; #endif // RECEIVER_H
#include "receiver.h" #include "ui_receiver.h" #include <QDBusConnection> Receiver::Receiver(QWidget *parent) : QMainWindow(parent), ui(new Ui::Receiver) { ui->setupUi(this); QDBusConnection bus = QDBusConnection::sessionBus (); if (bus.isConnected()) if (bus.registerService ("org.example.receiver")) if (bus.registerObject ("/", this, QDBusConnection::ExportAllSlots)) ui->textEdit->append ("Ready"); } Receiver::~Receiver() { delete ui; } void Receiver::hello (QString s) { ui->textEdit->append ("Hello: " + s); } QString Receiver::hello2 (QString s) { ui->textEdit->append ("Hello2: " + s); return "Answer from Receiver"; }
#include <QDBusConnection> #include <QDBusInterface> void Sender::on_actionRun_triggered() { QDBusConnection bus = QDBusConnection::sessionBus(); QDBusInterface ifc ("org.example.receiver", "/", "", bus); ifc.call ("hello", "Hello from Qt"); }
dbus.txt · Last modified: 2015/04/13 14:51 by 127.0.0.1