[Interest] Doubt extending my app functions ability
Bob Hood
bhood2 at comcast.net
Fri Jan 13 16:08:22 CET 2017
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
>
> classPInterface:publicQObject
>
> {
>
> Q_OBJECT
>
> public:
>
> explicitPInterface(QObject*parent=0);
>
> virtualQString/Name/()const=0;
>
> signals:
>
> publicslots:
>
> };
>
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:
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
{
Q_OBJECT
public:
virtual PInterface* newInstance() = 0;
};
QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(PInterfaceFactory, "org.Ernesto.PInterfaceFactory")
QT_END_NAMESPACE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170113/8b97be61/attachment.html>
More information about the Interest
mailing list