Hi,
in my application there is a bunch of plugins (all implementing the same interface) that communicate with the "core application" via the signal/slot mechanism. Each plugin has a getComm() method which returns the interface class (comm object) that contains the signals/slots (and the data structures) to enforce communication between the plugin and the core application. The comm class is a private member of the plugin class.
When a plugin needs data from the core application, its Communication Interface object emits a "requestDataFromCoreApp" signal, which is connected to the pluginRequestReceiver slot in the core application.
When a plugin sends data to the core application, its Communication Interface object emits a "readyToSend" signal, which is connected to the pluginRequestReceiver slot in the core application as well (but, in this case, the data is passed as parameter to the slot).
Simplified code of the loader method in the core application:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
QDir pluginsDir = directoryOf("plugins");
foreach (QString fileName, pluginsDir.entryList(QDir::Files))
{
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
if (MyPlugin *pluginIFC = qobject_cast<MyPlugin*>(loader.instance())) {
interfaces.append(pluginIFC);
int j = getPluginIndexByName(pluginIFC->name());
if (j!=-1) {
myPluginsInterfaces[j] = pluginIFC->getPluginComm();
connect(myPluginsInterfaces[j], SIGNAL(readyToSend(PluginType,GenericDataExchange*)),
this(), SLOT(pluginRequestReceiver(PluginType,GenericDataExchange*)));
connect(myPluginsInterfaces[j], SIGNAL(requestDataFromCoreApp(PluginType)),
this(), SLOT(pluginRequestReceiver(PluginType)));
}
}
|
NOTES:
- the getPluginIndexByName function simply returns an int with the index assigned to that plugin.
- the interfaces object is declared as QList <MyPlugin*> interfaces;
- myPluginsInterfaces is declared as PluginCoreCommunicationInterface* myPluginsInterfaces[max_number_of_plugins];
In reply to a plugin's request, the core application will send the data by using the pluginComm.sendDataToPlugin(data) method which makes the plugin comm object emit a dataReceived() signal.
In each plugin's constructor the dataReceived() signal of the pluginComm class is connected to an appropriate slot in the plugin class (getDataFromCoreApp).
Simplified code of each plugin's constructor:
|
Source code
|
1
|
connect(this->pluginComm,SIGNAL(dataReceived()),this,SLOT(getDataFromCoreApp()));
|
This architecture WORKS. It simply works, EXCEPT for one particular plugin and I can't figure out why. I've checked everything I could think of: the signals are declared as such, and so are the slots; the signals are actually emitted; the code where the signal is fired is actually reached; the signal/slot connection doesn't make any warning appear in debug mode; the plugin that doesn't work has the same base structure as the others; it has the Q_OBJECT macro in the header file; it is recognized as a plugin, so it is loaded. It's just that the signal/slot mechanism doesn't work in that plugin: I don't get any error, nor warning. I've also tried to connect a test_signal() signal to a test_slot() slot within the same plugin, and to forcibly have it fired in the plugin's constructor but the slot is never reached.
Since I don't get any clue from the debugger on what the heck is going wrong, it's very difficult for me to figure it out. Maybe someone has had the same issue before, I've searched on google for an answer but no luck so far. Any ideas?
Thanks in advance for your help!