[英]dbus-send not working in shell script
I want Bluetooth tethering between my laptop (Debian 8) and my smartphone (Android). 我想在笔记本电脑(Debian 8)和智能手机(Android)之间进行蓝牙网络共享。
At the arch linux wiki ( https://wiki.archlinux.org/index.php/android_tethering#Tethering_via_Bluetooth ) 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'
在
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'
Linux Wiki( https://wiki.archlinux.org/index.php/android_tethering#Tethering_via_Bluetooth )上,我找到了以下命令: 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.
为了我的目的,我需要在QT应用程序中调用此命令。 Because of this i created a shell script.
因此,我创建了一个shell脚本。 But when executing the script nothing happens.
但是执行脚本时什么也没发生。 Same result when calling the command inside a new shell (
sh
). 在新的外壳程序(
sh
)中调用命令时,结果相同。
Does anybody have an idea how to get this working or another way? 有谁知道如何使这种工作或其他方式吗? My normal terminal is the default Debian terminal, '
Root Terminal
'. 我的普通终端是默认的Debian终端“
Root Terminal
”。
Thank you 谢谢
I solved it using the QDBus object. 我使用QDBus对象解决了它。 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;
}
and 和
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;
}
Finally i call: 最后我打电话给:
QString interface = getDBusInterface();
QList<QVariant> arguments;
arguments.append("nap");
QDBusMessage response = sendDBus("org.bluez",
interface,
"org.bluez.Network1",
"Connect",
arguments);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.