View Single Post
Posts: 51 | Thanked: 15 times | Joined on Apr 2009 @ ChengDu, SiChuan, P.R.C
#1
Hello,

I have a simple qt example would like working with D-Bus, but i got error when i launch it. some detail as following
Code:
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QStringList>
#include <QtDBus>

void method_1()
{
	qDebug() << "Demo_1 Method 1(in): ";

	QDBusConnection bus = QDBusConnection::sessionBus();
	QDBusInterface dbus_iface("org.freedesktop.Telepathy.ConnectionManager", "org/freedesktop/Telepathy/ConnectionManager", 
			"org.freedesktop.Telepathy.ConnectionManager", bus);
	QDBusReply<QStringList> reply = dbus_iface.call("ListProtocols");
	foreach (QString name, reply.value())
		qDebug() << name;
	qDebug() << "Demo_1 Method 1(out): ";
}

int main(int argc, char **argv)
{
	QCoreApplication app(argc, argv);

	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");
		return -1;
	}

	method_1();

	return 0;
}
and i run dbus-launch like this
Code:
dbus-launch --auto-syntax
then, i run that example and got the error like this
Code:
[sbox-DIABLO_X86: ~/qt_tmp/demo_1] > run-standalone.sh ./demo_1
Cannot connect to the D-Bus session bus.
To start it, run:
	eval 'dbus-launch --auto-syntax'
[sbox-DIABLO_X86: ~/qt_tmp/demo_1] >
Why the session bus is not connected? Dose anyone know how could qt working with D-Bus successful?

Last edited by funpig; 2009-05-06 at 14:23.