SteffenH SteffenH - 3 months ago 11x
Bash Question

dbus-send not working in shell script

I want Bluetooth tethering between my laptop (Debian 8) and my smartphone (Android).

At the arch linux wiki ( i found this command:

bus-send --system --type=method_call --dest='org.bluez' '/org/bluez/hci0/dev_C0_EE_FB_20_D7_00' org.bluez.Network1.Connect string:'nap'

When i execute it in the normal terminal everything works fine. For my purpose i need to call this command in a QT application. Because of this i created a shell script. But when executing the script nothing happens. Same result when calling the command inside a new shell (

Does anybody have an idea how to get this working or another way? My normal terminal is the default Debian terminal, '
Root Terminal

Thank you


I solved it using the QDBus object. First i create the following two methods:

QString MainWindow::getDBusInterface(){
    QString interface = "/org/bluez/hci0/dev";
    QStringList macParts = ui->selectedMac->text().toUpper().split(":");
    for (int i = 0; i < macParts.length(); i++){
        interface.append("_").append(macParts[i]); //MAC address to connect to from GUI
    return interface;


QDBusMessage MainWindow::sendDBus(QString destination, QString path, QString interface, QString method, QList<QVariant> arguments){
    QDBusMessage response;

    QDBusConnection system = QDBusConnection::systemBus();
    if (!system.isConnected())
        qFatal("Cannot connect to the D-Bus session bus.");
        return response;

    QDBusMessage message2 = QDBusMessage::createMethodCall(destination, path, interface, method);


    // synchronous call (not recommended, blocking)
    response = QDBusConnection::systemBus().call(message2);
    qDebug() << "response is: " << response;

    return response;

Finally i call:

QString interface = getDBusInterface();

QList<QVariant> arguments;
QDBusMessage response = sendDBus("org.bluez",