[Interest] Doubt extending my app functions ability
Konstantin Tokarev
annulen at yandex.ru
Fri Jan 13 16:15:50 CET 2017
13.01.2017, 18:08, "Bob Hood" <bhood2 at comcast.net>:
> 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.
Actually, it does not make much sense to create static-only plugins. Static plugins make sense if you want to build all or some plugins in shared and static modes in different configurations of your software and handle both modes with same code, e.g. Qt itself benefits from this feature.
>
> 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
>>
>> class PInterface : public QObject
>>
>> {
>>
>> Q_OBJECT
>>
>> public:
>>
>> explicit PInterface(QObject *parent = 0);
>>
>> virtual QString Name() const = 0;
>>
>> signals:
>>
>> public slots:
>>
>> };
>
> 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
> {
> Q_OBJECT
> public:
> explicit PInterface(QObject *parent = 0);
> virtual QString Name() const = 0;
>
> signals:
> public slots:
> };
>
> QT_BEGIN_NAMESPACE
> Q_DECLARE_INTERFACE(PInterface , "org.Ernesto.PInterface")
> QT_END_NAMESPACE
>
> And try again.
>
> Also, a couple of observations:
>
> * Add a virtual destructor to your interface class so destructors of subclasses are properly called.
> * 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
> {
> Q_OBJECT
> public:
> virtual PInterface* newInstance() = 0;
> };
>
> QT_BEGIN_NAMESPACE
> Q_DECLARE_INTERFACE(PInterfaceFactory, "org.Ernesto.PInterfaceFactory")
> QT_END_NAMESPACE
>
> ,
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
--
Regards,
Konstantin
More information about the Interest
mailing list