D-Bus: Qt DBus Examples

Going through the Qt Dbus example code and there isn’t much of an explanation as to how the examples are done.  Plus I haven’t found any helpful tutorials about QtDbus.  I will make a rough attempt at giving some explanation to the ‘RemoteControllerCar’ example. I using that example because it’s most like what I’ll be doing where the server and client code will be in different programs.

The IDL is car.xml

 <node name="/com/trollech/examples/car">
         <interface name="com.trolltech.Examples.CarInterface">
                 <method name="accelerate"/>
                 <method name="decelerate"/>
                 <method name="turnLeft"/>
                 <method name="turnRight"/>
                 <signal name="crashed"/>
         </interface>
 </node>

What does this .xml file defining? It defines the interface with funtion names and argument that will be available to call between the two programs.

In this case, there are functions:

  • accelerate
  • decelerate
  • turnLeft
  • turnRight

In this RemoteControllerCar example the car acts as the server, and the controller is the client.

To compile the xml interface for the car (server):

Server stub (adaptor):

$ qdbusxml2cpp -c CarInterfaceAdaptor -a car_adaptor.h:car_adaptor.cpp car.xml

To compile for the controller (client):

Client proxy:

$ qdbusxml2cpp -v -c CarInterface -p car_interface.h:car_interface.cpp car.xml

Important parts in Car:

In main.cpp ln 66-69. That is how you add our D-Bus interface and connect to the D-Bus

Important parts in Controller:

In controller.cpp ln 50-51. This is how to connect to our D-Bus interface.

References:

Nokia QtDbus quick tutorial

OK need to cut it short. Got to implement something like this now.

Advertisements
This entry was posted in Coding, Linux, Qt and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s