How to release the plugin's dll file when application is running
-
i'am very very sorry,I haven't seen that reply before
by the way, I tried to use ploader - > setloadhints (0); Still can't succeed
It is said that it can work normally in the historical version of QT
please read this: https://ask.csdn.net/questions/1059003 -
@qtyangyong I doubt @JonB can read Chinese, I also can't.
"historical version of QT" - what does this mean? Do you mean old Qt version? What Qt version do you use? -
https://ask.csdn.net/questions/1059003
In that article, it said Qt5 4.2 has no such problems.
I try to use 5.12.10, 5.12.12 and 5.15.2, all have such problems -
Because of repeated questions, this question is merged into https://forum.qt.io/topic/136392/how-to-release-the-plugin-s-dll-file/7 , please don't reply here, thank you.
by the way, the dll file can not be deleted event if pluginLoader.setLoadHints(0); is called.[EDIT: Both topics are now merged. --JKSH]
-
Unloading a plugin will not remove it from the internal structures since there might be still references to this plugin somewhere so it might crash otherwise. There is a lengthy discussion about this on the Qt dev mailing list some years ago. Was in conjunction with QStringLiteral iirc.
-
With regard to the use of dynamic libraries, the basic principle is to release when the last user exits. If it is not released, the dynamic library cannot be hot updated. In this way, we need to add a dynamic library version control module in the application, use a new name for each update, and delete useless files when the application restarts.
by the way, I tried, as long as loader->instance(); is called, the DLL file is locked. It has nothing to do with the call of loader->unload(). Is it possible that the unload method did not close the handle of the DLL file?
-
@qtyangyong said in How to release the plugin's dll file?:
With regard to the use of dynamic libraries, the basic principle is to release when the last user exits. If it is not released, the dynamic library cannot be hot updated. In this way, we need to add a dynamic library version control module in the application, use a new name for each update, and delete useless files when the application restarts.
I learned recently, that, while you cannot delete a .dll or .exe on Windows that is currently used, you can rename it (as long as the library or executable is still in the same folder).
So maybe you can just rename the .dll, extract the new .dll, and after a restart delete the old .dll?
-
You should take a look at QLibrary::setLoadHints()
-
Hi, on Windows removing .dll and .exe files that have been recebtly used is not likely to succeed due tio caching etc.
Why don”t you instead try renaming your plugin file to something like DeleteMe.dll? That usually works. After that, you can create a new copy with the original filename, and then you”ll have full read/write/delete acccess.
-
@hskoglund said in How to release the plugin's dll file when application is running:
Hi, on Windows removing .dll and .exe files that have been recebtly used is not likely to succeed due tio caching etc.
Exactly!
-
@Christian-Ehrlicher
thans, I tried it but didn't solve the problem. Maybe the usage is incorrect.
such as
loader.setloadhints (0);
loader.unload(); -
@qtyangyong said in How to release the plugin's dll file when application is running:
Maybe the usage is incorrect.
For sure - they're load hints, not unload hints... set it before you load the library.
-
thank you very much, I moved "loader.setLoadHints(0);" before "loader.instance();", the problem was solved. the program such as below:
int main(int argc, char *argv[])
{
......
QPluginLoader loader("ExtraFiltersPlugin.dll");
loader.setLoadHints(0);
QObject *plugin = loader.instance();
if (plugin)
{
FilterInterface *fff = qobject_cast<FilterInterface *>(plugin);
fff->test();
}
MainWindow w;
w.ploader = &loader;
......
}void MainWindow::on_unloadBtn_clicked()
{
ploader->unload();
}