Unsolved Global function access to all plugins
-
@SGaist I dont understand how will I be able to access other plugin objects using such interface.
-
Currently I have used the following work around:
1)Load all the plugins in main.cpp.
2)Use the instance() function to get the base QObject instance of each plugin. Register these objects with an object name.
3)Since qApp is a global pointer to QApplication instance, make all QObjects a child of qApp.
4)use qApp pointer in all plugins to get any plugin instance i need, using findChildren().
5)I use an interface file to cast the QObject into a type which the base class of the plugin inherits from and then I am able to use all funtions from the interface, whose definition are on that plugin.
6)Also in order to take care of Plugin loading readiness. I have made a signal, which I call at the end of main.cpp, after all plugins have been loaded and connected to slot of all plugins defined in interface. So, all actions that require other plugins to be ready are performed in this slot of each pluginThis works for me but I was looking for a neater alternative. Alternate to using qApp, I came up with this idea about a global class / pointer / function /variable.
What is your comment on this @SGaist ? -
That you have a design issue.
If you need your plugins to know a lot of stuff about other plugins then clearly there's something wrong going on.
Are you sure that you need plugins at all ?
The role of a plugin is to extend a functionality and if it's not there then the extension is simply not available. Here you have them so tightly coupled that it defeats the goal of the plugin itself.
-
@SGaist according to https://doc.qt.io/qt-5/plugins-howto.html
Qt provides two APIs for creating plugins:A high-level API for writing extensions to Qt itself: custom database drivers, image formats, text codecs, custom styles, etc. A low-level API for extending Qt applications.
So I am making lower level APIs. And my plugins are extending my main Qt Application. Only the thing is PLugins may have dependency on each other too
Basically I want to achieve collaborative development using Plugins, where each developer can work on his Qt plugin. And one plugin can have dependency on another.
-
Isnt Qt Plugins a good way to achieve collaborative development ?
-
@Luckless said in Global function access to all plugins:
Isnt Qt Plugins a good way to achieve collaborative development ?
Can't you simply use shared libraries instead of plug-ins?
-
Actually Earlier I was using Shared Libraries. But Later I came across QT Plugins, and the instance() function that QPluginLoader provides to get the object of root node of the plugin, which I believe is not provided by QLibrary.
For this reason I went for Plugins over simple Shared Libraries. Is that bad @jsulm ? -
@Luckless Sounds like singleton class. Create your own. Do what you want inside.
-
@Luckless said in Global function access to all plugins:
Is that bad @jsulm ?
The question is rather: do you need plug-ins? Plug-ins are like shared libraries but are loaded at runtime when activated (just like what QtCreator is doing). And as pointed out by others they should not depend on each other. So, if your plug-ins are always needed by your application then I don't see the point to implement them as plug-ins, make them normal shared libraries.
-
Lets say I revert back to my Shared library / QLibrary code.
How would I achieve the following:@Luckless said in Global function access to all plugins:
To get the QObject instance of other plugins, via the central repo of objects(QHash(QString, QObject*))
And would it be any different if I try to achieve this in either Plugin or Shared Library case
-
@Luckless If you do not use plug-ins there is no need to get instances of other plug-ins.
If you need use functionality of lib a in lib b then do it in the usual way: include a header file in b and use the functionality.