SIGNAL deviceDiscovered is not emitting with C++ application.
-
Hi,
I have developed a library which exposes some APIs. This API is called by a c++ application. While calling a API, SDK start to discover the BLE devices. For this, I have called the start function of the class QBluetoothDeviceDiscoveryAgent. Following is the code snaps related the problem.
connect(m_discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo &)),
this, SLOT(addDevice(const QBluetoothDeviceInfo &)));m_discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
//Here m_discoveryAgent is the object of QBluetoothDeviceDiscoveryAgent.
Problem: Once I have called the start function. Then Ideally it should discover the devices, and deviceDiscovered signal should be emitted. But this signal is not emitted and so it's slot is not called. This is happened with C++ application. I have created a application using Qt also. This Qt Gui application is working fine.
I am assuming it may be reason that c++ application getting exit after start function is called by library. It is not waiting for executing the slot "addDevice" or emiting the signal deviceDiscovered in the library. While Qt application is a gui application, it remains in active state, so it is able to get execute the slots "addDevice".
-
Hi,
I have developed a library which exposes some APIs. This API is called by a c++ application. While calling a API, SDK start to discover the BLE devices. For this, I have called the start function of the class QBluetoothDeviceDiscoveryAgent. Following is the code snaps related the problem.
connect(m_discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo &)),
this, SLOT(addDevice(const QBluetoothDeviceInfo &)));m_discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
//Here m_discoveryAgent is the object of QBluetoothDeviceDiscoveryAgent.
Problem: Once I have called the start function. Then Ideally it should discover the devices, and deviceDiscovered signal should be emitted. But this signal is not emitted and so it's slot is not called. This is happened with C++ application. I have created a application using Qt also. This Qt Gui application is working fine.
I am assuming it may be reason that c++ application getting exit after start function is called by library. It is not waiting for executing the slot "addDevice" or emiting the signal deviceDiscovered in the library. While Qt application is a gui application, it remains in active state, so it is able to get execute the slots "addDevice".
@ankursaxena Did you make sure connect() succeeded?
Please connect a slot to https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#error-1 to see whether you get any errors."This is happened with C++ application. I have created a application using Qt also" - what does this mean? A Qt application is a C++ application (except you're using pure QML).
-
@ankursaxena Did you make sure connect() succeeded?
Please connect a slot to https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#error-1 to see whether you get any errors."This is happened with C++ application. I have created a application using Qt also" - what does this mean? A Qt application is a C++ application (except you're using pure QML).
@jsulm . I have updated my post. So that my problem can be understand easily. I have created a library (.so) and two applications which are having approx same kind of code and calling APIs exposed by the library. One application is purely C++ application and one is Qt based gui application. Ot based gui application is working fine. It is able to find discovered bluetooth devices and able to complete BLE transaction. While C++ application can not get discovered devices.
when I debug C++ application, I track and found that it calls start function in library. Then it should emit the deviceDiscovered signal. But Somehow, Flow comes out of library and C++ application executed their all the code lines and closed itself.
-
@jsulm . I have updated my post. So that my problem can be understand easily. I have created a library (.so) and two applications which are having approx same kind of code and calling APIs exposed by the library. One application is purely C++ application and one is Qt based gui application. Ot based gui application is working fine. It is able to find discovered bluetooth devices and able to complete BLE transaction. While C++ application can not get discovered devices.
when I debug C++ application, I track and found that it calls start function in library. Then it should emit the deviceDiscovered signal. But Somehow, Flow comes out of library and C++ application executed their all the code lines and closed itself.
@ankursaxena I guess you do not have a Qt event loop running in your C++ app? Without event loop signals/slots will not work.
-
@ankursaxena I guess you do not have a Qt event loop running in your C++ app? Without event loop signals/slots will not work.
@jsulm I have developed my library using Qt. But I want that a developer who does not have installed Qt, he/she should be able to integrate my library in pure c++ application. Is it possible ?
I don't know about Qt event loop. How this thing can be achieved in C++ without Qt ?
-
@jsulm I have developed my library using Qt. But I want that a developer who does not have installed Qt, he/she should be able to integrate my library in pure c++ application. Is it possible ?
I don't know about Qt event loop. How this thing can be achieved in C++ without Qt ?
@ankursaxena Well, if you want to use Qt in an application this application becomes a Qt application. There is no other way, even if the Qt part is in a lib.
The event loop is started when calling QApplication::exec(), which is a blocking call.QApplication app; ... return app.exec(); // Here Qt event loop is started
So, somewhere you have to start the Qt event loop. Since exec() call is blocking you would need to put whole Qt part of the app into its own thread.
"How this thing can be achieved in C++ without Qt ?" - it can't because Qt has its own event loop which you need to start.