Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

Zugdud picture Zugdud · Aug 1, 2015 · Viewed 8k times · Source

I have a QT/C++ terminal application which binds to D-Bus, but when I attempt to bind on the session bus I'm getting the following error:

"Unable to autolaunch a dbus-daemon without a $DISPLAY for X11"

This is just a simple terminal application, code snippet:

if (!QDBusConnection::sessionBus().isConnected()) {
    fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
                    "To start it, run:\n"
                    "\teval `dbus-launch --auto-syntax`\n");
    fprintf(stderr, "%s\n",
            qPrintable(QDBusConnection::sessionBus().lastError().message()));
    return 1;
}

I don't need X11 support, so I'm just looking for the easiest way to deal with this error

Answer

Zugdud picture Zugdud · Aug 4, 2015

For anyone who is interested, I just set env variables from within the program:

setenv("DISPLAY", ":0", true);