For demonstration purposes, I shall be logged in remotely on my home machine via ssh. If I run qdbus as per the last tutorial it fails immediately.
cm@pablo:~> qdbus
Could not connect to D-Bus server: org.freedesktop.DBus.Error.Spawn.ExecFailed: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.
What's really happening here is that qdbus is looking for the all important shell variable DBUS_SESSION_BUS_ADDRESS which contains a unique address for each bus. Not finding this, it's running dbus-launch --autostart to try and determine the address by querying another X window. Of course it then fails if it is unable to connect to any X session.
The obvious way to get around this is to set this variable. But how do we determine the bus address that we need to connect to our running instance of a program? This is not difficult, but it's not the most obvious method. As far as I am aware, there is no other easy way to do this - perhaps in future versions this will become more trivial.
The first thing to do is determine the PID of the app that we are after (ktorrent as in the last example).
cm@pablo:~> ps -ef|grep -i ktorrent
cm 4685 1 1 08:50 ? 00:06:17 ktorrent
cm@pablo:~> cat /proc/4685/environ
export DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-tIGLky9nbN,guid=49eaa775154aa8aa83ba330048070013"
cm@pablo:~> qdbus
:1.0
org.ktorrent.ktorrent
:1.2
org.kde.klauncher
:1.3
org.kde.kded
org.kde.kwalletd
:1.69
:1.70
org.freedesktop.DBus