QT5 + DLL loader (run-time)
-
@aha_1980 thanks for your quick response again and your good clarification about this topic.
Well, I saw the Plug&Paint (the main application part) and Plug&Paint Basic Tools (the Plugins part) QT examples...
The main application is usingQPluginLoader
to load the "Basic Tools" static library plugins. Ok!In this QT example, the Plug&Paint application NOT compiles before compile the "Basic Tools" QT Project. I think that's because the "Basic Tools" output is a static library, and this static library (*.lib) is dependence library of Plug&Paint project.
So, first of all, I need to compile "Basic Tools" project -> so, I get the output static lib file -> and then compile "Plug&Paint" main application.
My goal is different: I would like to develop a QT main application that doesn't have any "plugin dependencies" at compile time.
The plugins must extend the main application only in run-time.My future plugins should be a mix of "Fortran + QT GUI + C++".
Question: 1
Is there a "good practice" to develop this compile-time independent "main application"?
May be examples, tutoriais, etc...Question 2:
What is the best "QT Creator project type" to develop this GUI plugin? Why?
a) QT Plugin?
b) Dynamic Lib?
c) Static Lib?
d) Other?Question 3:
What is the "best way" to load these plugins in run-time? Why?
a) UsingQPluginLoader
?
b) UsingQLibrary
?@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 :-)
-
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
@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,
-
@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,
-
What is MyPrototype exactly ?
-
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
@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
-
@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.