Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QT5 + DLL loader (run-time)

QT5 + DLL loader (run-time)

Scheduled Pinned Locked Moved Solved 3rd Party Software
19 Posts 4 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.
  • F fem_dev

    @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 using QPluginLoader 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) Using QPluginLoader?
    b) Using QLibrary?

    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by
    #10

    @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

    Qt has to stay free or it will die.

    1 Reply Last reply
    3
    • hskoglundH Online
      hskoglundH Online
      hskoglund
      wrote on last edited by
      #11

      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 :-)

      1 Reply Last reply
      4
      • F Offline
        F Offline
        fem_dev
        wrote on last edited by
        #12

        Thank you so much @aha_1980 , @SGaist and @hskoglund ....now I'm getting the main idea about QPluginLoader and QLibrary. You guys help me a lot!

        I will try to do a simple code here.

        All the best!

        1 Reply Last reply
        1
        • aha_1980A aha_1980

          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 cast

          How 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: a void function taking three pointers to int as parameter. Note that you are defining a pointer to this function, because that is what myLib.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

          F Offline
          F Offline
          fem_dev
          wrote on last edited by
          #13

          @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_1980A 1 Reply Last reply
          0
          • F fem_dev

            @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_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #14

            @fem_dev

            I've no compiler at hand now, but I thought that should work...

            Qt has to stay free or it will die.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #15

              What is MyPrototype exactly ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • aha_1980A aha_1980

                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 cast

                How 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: a void function taking three pointers to int as parameter. Note that you are defining a pointer to this function, because that is what myLib.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

                F Offline
                F Offline
                fem_dev
                wrote on last edited by
                #16

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

                How 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: a void function taking three pointers to int as parameter. Note that you are defining a pointer to this function, because that is what myLib.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_1980A 1 Reply Last reply
                0
                • F fem_dev

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

                  How 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: a void function taking three pointers to int as parameter. Note that you are defining a pointer to this function, because that is what myLib.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_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #17

                  @fem_dev

                  Please try this:

                  MyPrototype sub = reinterpret_cast<MyPrototype>(myLib.resolve("sub"));

                  I'm pretty sure that will work.

                  Qt has to stay free or it will die.

                  F 1 Reply Last reply
                  2
                  • aha_1980A aha_1980

                    @fem_dev

                    Please try this:

                    MyPrototype sub = reinterpret_cast<MyPrototype>(myLib.resolve("sub"));

                    I'm pretty sure that will work.

                    F Offline
                    F Offline
                    fem_dev
                    wrote on last edited by
                    #18

                    @aha_1980 thank you so much!
                    It works!!

                    @aha_1980 you are the best!

                    Thank you again!

                    aha_1980A 1 Reply Last reply
                    1
                    • F fem_dev

                      @aha_1980 thank you so much!
                      It works!!

                      @aha_1980 you are the best!

                      Thank you again!

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #19

                      Hi @fem_dev,

                      I'm flattered, and glad I could help you.

                      Regards

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      1

                      • Login

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