0

My solution is currently to use a Singleton in a DLL that is located in a subdirectory. To get the singleton to work I used https://stackoverflow.com/a/21370524/9909548. And to use the DLL from the subdirectory I use https://stackoverflow.com/a/36644602/9909548 with an embedded Manifest and another one in the "iconengines" dir. To trigger an update I added a QSignal to the pure virtual singleton interface and also exported it.

Why I choose this approach:

  • DLL location: the DLL is a Qt IconEngine Plugin which, to my knowledge, must be located in the subdirectory "iconengines". (https://doc.qt.io/qt-5/plugins-howto.html)
  • Singleton: the plugin shall edit .svg's it loads (e.g. changing the color). It, therefore, needs to know some application state (e.g. the color to use). As the Plugin is automatically loaded by Qt I cannot directly set/update a member variable of the plugin.
  • Singelton Location: the IconEngine DLL should be used by several projects, therefore it cannot be located in the application sources (which would work otherwise).
  • Manifests: for the Singleton to actually be a Singleton and not instantiated several times it must be loaded from the same DLL (e.g. copying the DLL to "iconengines" AND the executable directory will not work).

Non-Options (mostly taken from https://ibob.bg/blog/2018/12/16/windows-rpath/ and Altering DLL search path for static linked DLL):

  • Adding the "iconengines" subdirectory to PATH or Registry or VS IDE
    • -> The solution should be portable and applicable to developers and customers. customers might not have admin privileges
  • Using .NET with a configure file
    • -> I canot use .NET
  • Patching the path in the created EXE after build
    • -> NO!
  • Using SetDllDirectory to add the "iconengines" to global DLL search dirs
    • -> the article that lists it as an option also discourages using it
  • Using LoadLibrary to access/edit the Singleton (C++ Load DLL From a Subdirectory?)
    • -> this would make using the singleton in various places annoying

My solution seems quite complicated for my initial goal to just let some Qt IconEngine Plugin depend on the application state. Is there a simpler/better/intended approach?

(if not clear from the tags: I am using Windows, CMake, C++, Qt)

Warmy
  • 155
  • 11

0 Answers0