Seite 1 von 1

QDBus: Interface mit einer einzigen Methode erzeugen

Verfasst: 4. April 2010 14:00
von hakaishi
Hallo,

in meinem Programm lasse ich ein Objekt mit seinen public slots exportieren, allerdings sind dann Methoden dabei, die ich nicht zugänglich machen möchte.
Wie ich weiß, gibt es die Möglichkeit das alles mit QDBusAbstractAdaptor (siehe Bsp.: http://doc.trolltech.com/4.5/qdbusadaptorexample.html) zu tun, allerdings verstehe ich dessen Funktion bzw. Handhabung nicht ganz.
Kann mir da jemand helfen? - Gibt es vielleicht noch eine einfachere Möglichkeit das zu erreichen, ohne QDBusAbstactAdaptor zu benutzen?

Der Quelltext zu dem o.g. Programm ist hier zu finden:
http://launchpad.net/qt-shutdown-p/qshu ... rig.tar.gz

Hier noch die Ausgabe bei dem Befehl "dbus-send --session --dest=org.qshutdown --print-reply /org/qshutdown org.freedesktop.DBus.Introspectable.Introspect":

Code: Alles auswählen

string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
  <interface name="local.Gui">
    <method name="showRunningProgram">
    </method>
  </interface>
  <interface name="com.trolltech.Qt.QWidget">
    <method name="setEnabled">
      <arg type="b" direction="in"/>
    </method>
    <method name="setDisabled">
      <arg type="b" direction="in"/>
    </method>
    <method name="setWindowModified">
      <arg type="b" direction="in"/>
    </method>
    <method name="setWindowTitle">
      <arg type="s" direction="in"/>
    </method>
    <method name="setStyleSheet">
      <arg name="styleSheet" type="s" direction="in"/>
    </method>
    <method name="setFocus">
    </method>
    <method name="update">
    </method>
    <method name="repaint">
    </method>
    <method name="setVisible">
      <arg name="visible" type="b" direction="in"/>
    </method>
    <method name="setHidden">
      <arg name="hidden" type="b" direction="in"/>
    </method>
    <method name="show">
    </method>
    <method name="hide">
    </method>
    <method name="setShown">
      <arg name="shown" type="b" direction="in"/>
    </method>
    <method name="showMinimized">
    </method>
    <method name="showMaximized">
    </method>
    <method name="showFullScreen">
    </method>
    <method name="showNormal">
    </method>
    <method name="close">
      <arg type="b" direction="out"/>
    </method>
    <method name="raise">
    </method>
    <method name="lower">
    </method>
  </interface>
  <interface name="org.freedesktop.DBus.Properties">
    <method name="Get">
      <arg name="interface_name" type="s" direction="in"/>
      <arg name="property_name" type="s" direction="in"/>
      <arg name="value" type="v" direction="out"/>
    </method>
    <method name="Set">
      <arg name="interface_name" type="s" direction="in"/>
      <arg name="property_name" type="s" direction="in"/>
      <arg name="value" type="v" direction="in"/>
    </method>
    <method name="GetAll">
      <arg name="interface_name" type="s" direction="in"/>
      <arg name="values" type="a{sv}" direction="out"/>
      <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/>    </method>
  </interface>
  <interface name="org.freedesktop.DBus.Introspectable">
    <method name="Introspect">
      <arg name="xml_data" type="s" direction="out"/>
    </method>
  </interface>
</node>
"
Wie man sehen kann sind hier viele öffentliche Methoden von QWidget enthalten. Ich benötige jedoch lediglich "showRunningProgram" (siehe main.cpp).


Gruß, Hakaishi

Verfasst: 5. April 2010 03:05
von hakaishi
Wie kann ich eine einzelne Methode eines Objektes exportieren, sodass ich über DBus bzw. qdbus darauf zugreifen kann?

Verfasst: 5. April 2010 19:12
von hakaishi
Ich habe nun der gewünschten Methode ( Gui::showRunningProgram() ) ein Q_SCRIPTABLE vorangehängt (in gui.h) und dann mit QDBusConnection::ExportScriptableSlots exportiert (siehe main.cpp). Da meine Methode die einzige skriptfähige ist, ist diese Lösung IMHO akzeptabel, jedoch nicht die Lösung die ich haben möchte (wer weiß wie lange es die einzige bleibt)...
Wenn jemand eine bessere Idee hat, dann nur her damit :wink:

Der neue Quelltext ist hier zu finden.

Gruß, Hakaishi