Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I started to work with DBus and bluetooth in Qt. I want to develop a script that will just call method through DBus and get a reply. The part of the code is here (that is the main part acutally):

QString hostname("00:07:80:60:CE:22");
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusInterface interface("org.bluez", "/", "Manager", bus, 0);
qDebug()<<"is valid: "<<interface.isValid()<<interface.lastError();

interface.lastError() gives following error:

QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.bluez was not provided by any .service files")

I have bluez and dbus installed. I can search for bluetooth devices from command.

I also tried command sudo bluetoothd -d -n and I Get this: D-Bus setup failed: Name already in use bluetoothd[21952]: Unable to get on D-Bus

Does anyone know what could be a problem?

are you getting responses from dbus commands,try this command, if no response means bluez is not registered to dbus command: dbus-send --system --type=method_call --print-reply --dest=org.bluez "/" org.bluez.Manager.ListAdapters – ashish Aug 30, 2013 at 3:59 The interface name is incorrect? Try like this instead: QDBusInterface interface("org.bluez", "/", "org.bluez.Manager", bus, 0); – jaguzu Sep 24, 2013 at 8:39

The error you are getting (name already in use) means that the bluetooth daemon is already running on your system. You can stop it by doing sudo service bluetooth stop, although I feel like it is a pretty brutal way to end the bluetooth daemon. If you end the daemon, you also end the BlueZ D-Bus implementation, so you wouldn't be able to use it.

Although I've never worked with Qt's bluetooth/dbus implementation, there are a few problems with your code:

First of all, the BlueZ interface is published through the system bus, not the session bus, so that's the first change that should be made.

Second, what is the function of the "Manager" parameter your passing? If you are trying to hook into a DBus interface called "Manager" then there is none. I'm not sure if there was, seeing as you asked this question in 2013. You can see the DBus interfaces BlueZ implements using a program called D-Feet. You should try it out, as it has helped me understand the workings of BlueZ with DBus. I recommend sudo apt-get install d-feet. The only interfaces that are published at the "/" path are org.freedesktop.DBus.Introspectable and org.freedesktop.DBus.Objectmanager. Again, this can easily be seen and experimented with using D-Feet, as it allows visual representations of the abstract interfaces and paths.

If, by any chance, you run into trouble later regarding GATT; run bluetoothd with the -E experimental flag; this enables BlueZ GATT functionality. (Just a heads up).

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.