Shouldnt createInstance be static![]()
Shouldnt createInstance be static![]()
Normally it should, but as I use it in a plugin, there are some things that I wasn't really sure about.
1. Every interface should contain pure virtual functions, that's what I often read and tried to consider.
2. Loading the plugin always ends up in creating an instance of the plugin for trying to cast it to the interface afterwards.
That's why I didn't implement it as a static method.
But nevertheless, I tried your proposition and the problem seems to be something different.
Everything runs fine when I implement it like this:
Qt Code:
{ }To copy to clipboard, switch view to plain text mode
but when I try to return the pointer to an instance of TemplatePlugin, it always crashes or rather doesn't compile.
My class implements the interface and inherits QObject that's why I thought this should actually work.
So, how far am I from beeing completely wrong?![]()
The error looks like it is from the linker not the compiler. Have you got the LIBS right?
Failing that, how about posting (attach a file) a minimal compilable example that displays the linker error that you are complaining of.
Can you share the header for TemplatePlugin ?
ChrisW67:
Yeah you're right, it's actually a linker error. And I think that the LIBS should be alright, so I followed your proposal and set up a small example that shows my problem.
Actually, there's something I didn't mention about the interface. It is set up in a shared library and perhaps that's something were some problems arise from.
Whatever, I attached the small example so you can see exactly what I'm messing around with.
I'm sorry to annoy someone, but this problem is quite annoying.
I hope anybody can have a look over my attached project.
I realized that I haven't included QtPlugin but even if so, it doesn't solve the problem.
Thanks in advance!
Well, well.
I found the problem, quite a little bit stupid a have to admit.
So for anybody who has the same problem my sollution:
I have tried to use the following as interface header:
This has to fail, obviously in the end, because there is nothing to export/compile/link from a header.Qt Code:
#if defined(PLUGININTERFACE_LIBRARY) # define PLUGININTERFACESHARED_EXPORT Q_DECL_EXPORT #else # define PLUGININTERFACESHARED_EXPORT Q_DECL_IMPORT #endif class PLUGININTERFACESHARED_EXPORT PluginInterface { public: };To copy to clipboard, switch view to plain text mode
That's why I got the linker error.
So removing the following is the solution.Qt Code:
PLUGININTERFACESHARED_EXPORTTo copy to clipboard, switch view to plain text mode
Problem solved.
Bookmarks