On 1/12/2017 4:33 PM, Ernesto wrote:
Hello again, first, thanks to Bob Hood for his quickly reply.
I understood your explanation about my second problem, but I have another
issue writing your solution in an example project. I have a MainApp (QT
Widgets project) and a Lib1 (C++ Static Library project) and here is the code:
If you are creating statically linked plug-ins, that requires a different
approach. However, you also mention "the Lib1.dll file" elsewhere, so I
assume you are not.
I'm sure you have read the online docs about Qt plug-in, Ernesto, but probably
missed a subtle point which is evident in your interface file:
//This is header file of my interface, is included by both projects
You have to designate/declare the class that will be the plug-in interface.
Try adding the following declarations to your interface file "PInterface", so
it looks something like this:
class PInterface : public QObject
explicit PInterface(QObject *parent = 0);
virtual QString Name() const = 0;
** Q_DECLARE_INTERFACE(PInterface , "org.Ernesto.PInterface")**
And try again.
Also, a couple of observations:
1. Add a virtual destructor to your interface class so destructors of
subclasses are properly called.
2. If you'll notice my original code example, I use QPluginLoader to load a
factory instance. The Qt plug-in system (QPluginLoader) *does not do
multiple instancing of plug-ins*. Therefore, if you will need multiple
copies of any given plug-in you load, you'll need to use the Factory
Pattern within each plug-in shared library to generate and return
instances, and then designate the Factory class interface as the Qt
plug-in interface instead; e.g.:
class PInterfaceFactory : public QObject
virtual PInterface* newInstance() = 0;
Interest mailing list