Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to release the plugin's dll file when application is running
Forum Updated to NodeBB v4.3 + New Features

How to release the plugin's dll file when application is running

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 7 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtyangyong
    wrote on last edited by
    #13

    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?

    1 Reply Last reply
    0
    • kkoehneK Offline
      kkoehneK Offline
      kkoehne
      Moderators
      wrote on last edited by
      #14

      @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?

      Director R&D, The Qt Company

      Q 1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #15

        You should take a look at QLibrary::setLoadHints()

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        Q 1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #16

          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.

          JonBJ 1 Reply Last reply
          2
          • kkoehneK kkoehne

            @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?

            Q Offline
            Q Offline
            qtyangyong
            wrote on last edited by
            #17

            @kkoehne yes, this is a good idea

            1 Reply Last reply
            0
            • hskoglundH hskoglund

              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.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #18

              @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!

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by hskoglund
                #19

                Sorry didn't read the above ...please don't reply here.. (use the other forum post), also I see in that post that @kkoehne already suggested the same thing, i.e. renaming the plugin :-)

                1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  You should take a look at QLibrary::setLoadHints()

                  Q Offline
                  Q Offline
                  qtyangyong
                  wrote on last edited by
                  #20

                  @Christian-Ehrlicher
                  thans, I tried it but didn't solve the problem. Maybe the usage is incorrect.
                  such as
                  loader.setloadhints (0);
                  loader.unload();

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • Q qtyangyong

                    @Christian-Ehrlicher
                    thans, I tried it but didn't solve the problem. Maybe the usage is incorrect.
                    such as
                    loader.setloadhints (0);
                    loader.unload();

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #21

                    @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.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • Q Offline
                      Q Offline
                      qtyangyong
                      wrote on last edited by
                      #22

                      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();
                      }

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved