2016-06-30 6 views
0

私のラップトップ(Debian 8)と私のスマートフォン(Android)の間にBluetoothテザリングが必要です。アーチのLinuxのwiki(https://wiki.archlinux.org/index.php/android_tethering#Tethering_via_Bluetooth)でdbus-sendがシェルスクリプトで動作しない

iは、このコマンドが見つかりました: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'

私は通常の端末すべてにそれを実行し正常に動作します。私の目的のためには、QTアプリケーションでこのコマンドを呼び出す必要があります。このため、私はシェルスクリプトを作成しました。しかし、スクリプトを実行すると何も起こりません。新しいシェル(sh)内でコマンドを呼び出すと同じ結果になります。

誰かがこの作業方法または別の方法を取得する方法を知っていますか?私の普通の端末はデフォルトのDebian端末 'Root Terminal'です。

ありがとう

+1

私は、例えば、スクリプトが実行されている環境を確認して開始したい最初のiは、次の2つのメソッドを作成します環境変数DBUS_SESSION_BUS_ADDRESSが設定されていない場合は、dbus-sendコマンドに他のアドレスを使用するか、呼び出しの前に変数を設定することができます。 Qtアプリケーションから実行する場合は、現在の環境を、たとえば呼び出しが行われる環境にコピーする方法を参照してください。 – JoGr

+0

あなたの答えをありがとう。他のdbus-sendコマンドはfindを検索しました。 QTのDBusクラスとメソッドを使って管理しました。 – SteffenH

答えて

0

QDBusオブジェクトを使用して解決しました。最後に私が呼ん

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); 

    message2.setArguments(arguments); 


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

    return response; 
} 

QString interface = getDBusInterface(); 

QList<QVariant> arguments; 
arguments.append("nap"); 
QDBusMessage response = sendDBus("org.bluez", 
            interface, 
            "org.bluez.Network1", 
            "Connect", 
            arguments); 
関連する問題