Question withdrawn - Passing system function to QProcess - need syntax help
-
I think I need to withdrew this question. After digesting more QT doc I realized that QProcess is NOT starting a new thread , hence in my case of time consuming "scan" it is just wrong to use it. QT has a "concurrency" "feature" which does start multiple threads... ]
system("hcitool -i hci0 scan --flush ");
This "system call " works as expected - it finds nearby Bluetooth devices in allotted time - - up to 15 seconds. I use is instead of many "bluez" library derived function because it works CONSISTENTLY... Because it blocks running thread for up to 15 seconds I like to utilize QT . "QProcess" object. I have it working using convoluted "bash" code
OProcess.start("/bin/sh", QStringList() << "-c" << "hcitool -i hci0 scan --flush >> /tmp/temp");
and like to utilize it WITHOUT "bashing". Something like this
QProcess::execute("system("hcitool -i hci0 scan --flush "));
of course it does not compile, hence I am here posting this. Any "unbashed" suggestions would be appreciated - in C or C++ . PS there are more options to be added to basic "hcitool" command.
-
I think I need to withdrew this question. After digesting more QT doc I realized that QProcess is NOT starting a new thread , hence in my case of time consuming "scan" it is just wrong to use it. QT has a "concurrency" "feature" which does start multiple threads... ]
system("hcitool -i hci0 scan --flush ");
This "system call " works as expected - it finds nearby Bluetooth devices in allotted time - - up to 15 seconds. I use is instead of many "bluez" library derived function because it works CONSISTENTLY... Because it blocks running thread for up to 15 seconds I like to utilize QT . "QProcess" object. I have it working using convoluted "bash" code
OProcess.start("/bin/sh", QStringList() << "-c" << "hcitool -i hci0 scan --flush >> /tmp/temp");
and like to utilize it WITHOUT "bashing". Something like this
QProcess::execute("system("hcitool -i hci0 scan --flush "));
of course it does not compile, hence I am here posting this. Any "unbashed" suggestions would be appreciated - in C or C++ . PS there are more options to be added to basic "hcitool" command.
The docs are pretty clear: [QProcess Class | Qt Core 5.15.8](https://doc.qt.io/qt-5/qprocess.html#:~:text=int QProcess%3A%3Aexecute(const QString %26program%2C const QStringList %26arguments)) Try
QProcess::execute("hcitool", "-i chio scan --flush");
since
hcitool
is part of the bluez package, it almost certainly uses the bluez library to do its work. If you can get hold of the source code, you should be able to look through it and find out why they make it work the way you expect it to.Keep Calm and Carry On
-
The docs are pretty clear: [QProcess Class | Qt Core 5.15.8](https://doc.qt.io/qt-5/qprocess.html#:~:text=int QProcess%3A%3Aexecute(const QString %26program%2C const QStringList %26arguments)) Try
QProcess::execute("hcitool", "-i chio scan --flush");
since
hcitool
is part of the bluez package, it almost certainly uses the bluez library to do its work. If you can get hold of the source code, you should be able to look through it and find out why they make it work the way you expect it to.Keep Calm and Carry On
I did try "splitting " program and argument - it did not pass compiler. Then I put all as a single parameter and it did not run at all.
OProcess.start("/bin/sh", QStringList() << "-c" << "hcitool -i hci0 scan --flush | tee >> /tmp/temp"); no tee ourput to console - not that important
qDebug() << OProcess.state(); returns "process starting" expected
qDebug() << OProcess.state(); returns "process starting" sort of expected
OProcess.waitForFinished();
//OProcess.state();
qDebug() << OProcess.state(); return process not running expectedOProcess.execute("hcitool-i hci0 scan --flush >>/tmp/temp");
qDebug() << OProcess.state(); return process not running not surprised
OProcess.waitForFinished();
OProcess.state();
qDebug() << OProcess.state(); return process not running obviousI am under the impression that "hci" was first - then "bluez" - based on "hci" The QT implementation of bluez is missing the "--flush" option in "scan". That keeps QT from actually scanning for devices and that is of no good....