Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SIGNAL deviceDiscovered is not emitting with C++ application.
Forum Updated to NodeBB v4.3 + New Features

SIGNAL deviceDiscovered is not emitting with C++ application.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 524 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ankursaxena
    wrote on last edited by ankursaxena
    #1

    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".

    jsulmJ 1 Reply Last reply
    0
    • A ankursaxena

      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".

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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).

        A Offline
        A Offline
        ankursaxena
        wrote on last edited by
        #3

        @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.

        jsulmJ 1 Reply Last reply
        0
        • A ankursaxena

          @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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ankursaxena I guess you do not have a Qt event loop running in your C++ app? Without event loop signals/slots will not work.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          1
          • jsulmJ jsulm

            @ankursaxena I guess you do not have a Qt event loop running in your C++ app? Without event loop signals/slots will not work.

            A Offline
            A Offline
            ankursaxena
            wrote on last edited by
            #5

            @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 ?

            jsulmJ 1 Reply Last reply
            0
            • A ankursaxena

              @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 ?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved