Solved Implementing bluetooth - general questions - part 1
-
Thanks to this forum support my bluetooth application frame / GUI is working as desired. Appreciate such support very much .
Now is the time to modify basic btscanner to consistently establish bluetooth devices connection and pass data thru it.
According to manuals, the Qt uses "blueZ" library.
Such library, which is basically hidden from direct access , throws errors when bluetooth process fails - generally in format
"qt.bluetooth.bluez ....."
and displays them on console at run time.My desire is to redirect these error / progress messages to Qt form / widget.
Any suggestions how to accomplish this would be greatly appreciated.
Cheers
-
QBluetoothServiceDiscoveryAgent
andQBluetoothDeviceDiscoveryAgent
haveerror
signals anderrorString()
functions, to which you can connect to and "simply" set thisQString errorString
to your menuBar or wherever you want to show it.Here is an example (might confuse you a bit, because it's using lambda connections). So no slot needed. Your code is right inside the connect-statement. But it's the usual way, how to use it, I guess.
connect(bluetoothDeviceDiscoveryAgent, QOverload<QBluetoothDeviceDiscoveryAgent::Error>::of(&QBluetoothDeviceDiscoveryAgent::error), [=](QBluetoothDeviceDiscoveryAgent::Error error){ // Place code to set your error to your ui here });
(From: https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#error-1)
You will receive the "human readable" error msg, by using this function:
QString QBluetoothDeviceDiscoveryAgent::errorString()
https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#errorString
-
QBluetoothServiceDiscoveryAgent
andQBluetoothDeviceDiscoveryAgent
haveerror
signals anderrorString()
functions, to which you can connect to and "simply" set thisQString errorString
to your menuBar or wherever you want to show it.Here is an example (might confuse you a bit, because it's using lambda connections). So no slot needed. Your code is right inside the connect-statement. But it's the usual way, how to use it, I guess.
connect(bluetoothDeviceDiscoveryAgent, QOverload<QBluetoothDeviceDiscoveryAgent::Error>::of(&QBluetoothDeviceDiscoveryAgent::error), [=](QBluetoothDeviceDiscoveryAgent::Error error){ // Place code to set your error to your ui here });
(From: https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#error-1)
You will receive the "human readable" error msg, by using this function:
QString QBluetoothDeviceDiscoveryAgent::errorString()
https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#errorString
-
Thanks, I need to pay more attention to doc , but I did nor realize how versatile signals / slots are.
-
It's all about signals and slots (almost) :-)
You don't like just reading the "manual" / docs, but you really should check out the docs of your classes, that you are currently using. All default signals, which could be emitted by this class are listed there. So it's always worth to take a look at it.
(The docs are accessible inside QtCreator by clicking / marking any Qt class (
QWhatever
) and pressing theF1
key. So you don't have to browse the internet and look for your class documentation. In case you didn't know that)