「Qtの基礎 - D-Bus」の版間の差分

ナビゲーションに移動 検索に移動
193行目: 193行目:
*: D-Busインターフェースファイルを生成する。
*: D-Busインターフェースファイルを生成する。
<br>
<br>
以下の例では、C++クラスからD-Busインターフェイスファイル (XMLファイル) を生成している。<br>
<br>
まず、インターフェイスを定義したC++クラスを作成する。<br>
<syntaxhighlight lang="c++">
// ExampleObject.h
#include <QObject>
#include <QString>
class ExampleObject : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "com.example.ExampleInterface")
public slots:
    QString exampleMethod(const QString &input)
    {
        return "Hello, " + input;
    }
};
</syntaxhighlight>
<br>
次に、<code>qdbuscpp2xml</code>コマンドを実行して、D-Busインターフェースファイル (XMLファイル) を生成する。<br>
以下の例では、ExampleObject.hファイルからインターフェイスを読み取り、ExampleInterface.xmlファイルを生成している。<br>
qdbuscpp2xml -m -s ExampleObject.h -o ExampleInterface.xml
<br>
生成されたD-Busインターフェースファイル (XMLファイル) を以下に示す。<br>
<syntaxhighlight lang="xml">
<!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="com.example.ExampleInterface">
    <method name="exampleMethod">
      <arg direction="in" type="s" name="input"/>
      <arg direction="out" type="s" name="output"/>
    </method>
  </interface>
</node>
</syntaxhighlight>
<br>
==== qdbusxml2cppコマンド ====
==== qdbusxml2cppコマンド ====
<code>qdbusxml2cpp</code>コマンドは、D-Busインターフェースファイルの定義に従い、C++のアダプターコードを生成する。<br>
<code>qdbusxml2cpp</code>コマンドは、D-Busインターフェースファイルの定義に従い、C++のアダプターコードを生成する。<br>

案内メニュー