Solved QT5 + DLL loader (run-time)
-
@fem_dev I suggest you to do a bit of information research yourself. As said, playing with existing examples also helps to understand how things work.
Me and @SGaist already gave examples how you could start your work.
Once again: plugins can be compiled separate from your app and can be loaded at runtime. That's what
QPluginLoader
helps you to do.QLibrary
is for loading external libraries, e.g. your pure FORTRAN libs.I really cannot tell you more, because I've used
QLibrary
a lot, but did not much with plugins so far.Regards
-
Hi, to add to @aha_1980: I've used both QLibrary and QPluginLoader, you could say QPluginLoader is a superset of QLibrary. I haven't looked at the source code, but QPluginLoader probably uses QLibrary to load the its plugin .dlls.
They're doing the same basic job, but QPluginLoader does much more checking and tidying up, so wiring up/talking to your .dlls in your app is easier going through QPluginLoader.
IOW, QPluginLoader is more high-level, like an automatic car, while QLibrary is more like driving a stick-shift car :-)
-
Thank you so much @aha_1980 , @SGaist and @hskoglund ....now I'm getting the main idea about
QPluginLoader
andQLibrary
. You guys help me a lot!I will try to do a simple code here.
All the best!
-
@aha_1980 this is the last doubt in this post:
When I try to follow your sugestion replacing this line:
MyPrototype sub = (MyPrototype) myLib.resolve("sub");
To:
MyPrototype sub = static_cast<MyPrototype>(myLib.resolve("sub"));
I got this compilation error:
error: static_cast from 'QFunctionPointer' (aka 'void (*)()') to 'MyPrototype' (aka 'void (*)(int *, int *, int *)') is not allowed
Coul you help me?
Thank you,
-
I've no compiler at hand now, but I thought that should work...
-
What is MyPrototype exactly ?
-
@aha_1980 said in QT5 + DLL loader (run-time):
Hi @fem_dev said in QT5 + DLL loader (run-time):
Question 1:
In the line:
MyPrototype sub = (MyPrototype) myLib.resolve("sub");I got this warning:
Use of old-style castHow to do a "new-style cast" and remove this warning?
MyPrototype sub = static_cast<MyPrototype>(myLib.resolve("sub"));
Question 2:
What is MyPrototype in this code? Why it works?You defined it yourself:
typedef void (*MyPrototype)(int*, int*, int*);
. This is just the signature of the function you are calling: avoid
function taking three pointers toint
as parameter. Note that you are defining a pointer to this function, because that is whatmyLib.resolve()
returns.Question 3:
Can I put QT GUI elements (Window, buttons, labels, etc...) inside a DLL file?Yes, but creating a real plugin with
QPluginLoader
is better suited for that.Regards
-
Please try this:
MyPrototype sub = reinterpret_cast<MyPrototype>(myLib.resolve("sub"));
I'm pretty sure that will work.
-
-