Results 1 to 7 of 7

Thread: QPluginLoader doesn't load dynamic plugin when accessing a static plugin

  1. #1
    Join Date
    Jul 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QPluginLoader doesn't load dynamic plugin when accessing a static plugin

    I'm playing with Qt Plugins and it's working fine so far. I can load a dynamic plugin (config += plugin) and access its methods from the main application without any problem.

    However, after creating another plugin, this time a static one (config += static) linked to the main, and trying to access anything of it from my first dynamic plugin, the dynamic plugin isn't recognized/loaded by QPluginLoader anymore.

    So here's my question: is it possible to access a static plugin from a dynamic plugin?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader doesn't load dynamic plugin when accessing a static plugin

    A static plugin is a kind of oxymoron.
    If it is static, its not a plugin, since it has to be linked IN to your application, so your application executable has it always in it, which is not what a plugin is, a plugin is optional, and CAN be used, but doesn't have to.
    So EITHER its a plugin, OR a static lib.
    A static plugin makes no sense.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPluginLoader doesn't load dynamic plugin when accessing a static plugin

    It's a static lib though (...). Anyone knows the answer of my question? Thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader doesn't load dynamic plugin when accessing a static plugin

    It's a static lib though
    Which is what I said:
    So EITHER its a plugin, OR a static lib.
    Anyone knows the answer of my question?
    Well what is the question?
    It simply is not clear:
    On one hand you say:
    The dynamic plugin isn't recognized/loaded by QPluginLoader anymore.
    So, if the plugin is not loaded no wonder it can't do anything.
    It has nothing to do (yet) with anything else such as accessing your static lib.

    On the other hand you ask this:
    is it possible to access a static plugin from a dynamic plugin?
    And again, the question makes no sense.

    Its like asking: "is it possible to be sick while healthy".
    Can you answer that?

    The dynamic plugin has no linking information about the static lib your application is linking against, so the very simple answer is "no".
    However there might be a way to allow this.
    Once you link to a static lib, you can see it as an integral part of your application.
    If you wish your application to allow access of the functionality it has from the static lib to the plugin, you could create wrapper methods that your plugin interface is can access, and in the implementation of these your application will call the static lib functions.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jul 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPluginLoader doesn't load dynamic plugin when accessing a static plugin

    @high_flyer, I don't think we need to go this way (although Qt Plugin page talks a lot about static plugins). The main point is not that. Let's try another way.

    My architecture is something like this:

    Core -> static lib
    MainWindow -> application
    Plugin A -> dynamic plugin

    Core is statically linked to main, and Plugin A is loaded dynamically by Core. My question is: since Core is known by MainWindow (they share let's say the same memory namespace), then Plugin A can see a method of Core? I'm asking this because when I try to create an instance of Core inside this Plugin A, although everything compiles and links without any problem, Plugin A stops to be recognized as valid plugin by QPluginLoader (i.e. instance() returns a null pointer).

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader doesn't load dynamic plugin when accessing a static plugin

    I don't think we need to go this way (although Qt Plugin page talks a lot about static plugins).
    Yes, the the essence of that text is that you get the plugin IN Qt.
    And since your application links to Qt you get the functionality from these plugins.

    This is not your setup however.
    Here your dynamic plugin takes the role of the application from the above setup.
    Your dynamic plugin is not linking against the application or the static plugin, (like the application linked to Qt above) thus it has no knowledge of the symbols in the static plugin/lib.

    And again, the simple answer is "no".
    There are ways to allow this, one I mentioned in the previous post.
    You can't go around the fact that your dynamic plugin needs to know the symbols of your static plugin/lib.
    Or otherwise put: whoever access the static libs functionality needs to know the symbols in it.

    BTW - this whole problem is an indicator to a design problem on several accounts.
    One, it seems the functionality encapsulation is not correct - as you need functionality from your static lib both in your app and your dynamic plugin.
    Which brings the question - why are you using static linking for one of the plugins?
    Then you have a problem of tight coupling and rigidness, which means you have bad decoupling of code.
    Having plugins depend on other plugins simply defeats the concept of plugins.
    The correct way to fix your problem would be to rethink the design - I am aware however, that this is not always an option.
    But through usage of interfaces and wrappers you could effect the design without changing it, at least to some degree.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jul 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPluginLoader doesn't load dynamic plugin when accessing a static plugin

    @high_flyer, I see. Thanks for the tips. I decided to insert a pointer of Core (static lib) into plugins after loading them. Maybe this is not the most beautiful solution, but it's working nice

    Thanks once again!

Similar Threads

  1. QPluginLoader doesn't accept plugin name
    By Gourmet in forum Qt Programming
    Replies: 3
    Last Post: 8th June 2011, 15:01
  2. QPluginLoader not load plugin
    By Thyago.celler in forum Qt Programming
    Replies: 9
    Last Post: 20th May 2011, 19:01
  3. QPluginloader load plugin from RAM
    By meCHAoT in forum Qt Programming
    Replies: 3
    Last Post: 3rd February 2011, 17:23
  4. Replies: 8
    Last Post: 27th December 2009, 14:57
  5. QPluginLoader doesn't load plugin
    By BeS in forum Qt Programming
    Replies: 6
    Last Post: 26th November 2008, 19:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.