Question

I'm having a QCoreApplication that loads different QtPlugins during startup that are getting data from various sources. This data is pushed back to my QCoreApplication through a registered callback function (equal for each plugin). The callback is registered as follows:

// m_manager is a class variable of the class registering the callback...
pluginInterface->registerCallback(std::bind(&Manager::handleData, std::ref(m_manager), _1));

Now I'm having the following problem: In one of the plugins data is received by a third-party library via network. The data will be pushed to a static member function of my plugin class together with a self-defined struct that also contains the this pointer to the plugin class. When I'm receiving the data in the plugin I now want to push it to my QCoreApplication through the registered callback. Additionally, I want to create new objects (like QTimer) in the callback function. However, it seems like no event loop is running when calling the callback function from the static member function through the this pointer of the plugin class. When looking through the members of the created QTimer object, its QAbstractEventDispatcher pointer is 0. Thus, no signals can be emitted by the QTimer object, which is what I desperately need.

I thought that calling the callback function through the this pointer of the plugin class (where a QEventLoop is definitely running, since I can use signals/slots inside the plugin and from other non-static member functions of the plugin to my QCoreApplication without a problem). However, it seems like I'm wrong. Does anyone have an explanation for the described behavior? If there are any other details needed, just ask for them and I'll try to provide them.

Regards, Robert

Was it helpful?

Solution

If the library is synchronous and doesn't return control flow to the event loop, it keeps being busy and can't invoke slots. You need to create a thread and perform synchronous operations in that thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top