无法终止在Linux上运行hcitool的QProcess?

时间:2016-11-20 10:52:19

标签: linux qt bluetooth-lowenergy bluez

我正在尝试使用Linux / Bluez工具:hcitool,从QT进行BLE扫描。

我使用以下内容打开过程:

QString program = "sudo stdbuf -oL hcitool -i hci0 lescan";
hcitool = new QProcess();

connect(hcitool, SIGNAL(started()), this, SLOT(hcitool_started()));
connect(hcitool, SIGNAL(finished(int)), this, SLOT(hcitool_finished(int)));
connect(this, SIGNAL(kill_hcitool()), hcitool, SLOT(kill()));
connect(this, SIGNAL(terminate_hcitool()), hcitool, SLOT(terminate()));

hcitool->start(program, QProcess::Unbuffered | QProcess::ReadWrite);

然后我不断阅读该过程以存储所有结果:

QString result = hcitool->readLine();

几秒钟后,我想停止hcitool进程,这就是出错的地方。我已经尝试了终止信号,杀死信号,将^ C写入进程,但没有任何作用。

实际上,kill信号完成了这个过程。但不是很好,因为之后我的hci0被阻止了,在重置hci0之前我无法再次启动hcitool:

hciconfig hci0 down
hciconfig hci0 up

那么我对如何终止这个过程有任何想法吗?

1 个答案:

答案 0 :(得分:1)

(从评论中移出)

通常有效的技巧只是close()流,它应该为子进程提供SIGHUP或SIGPIPE,这通常可以更优雅地处理。