[SOLVED] How to tell QPluginLoader to check for dll dependencies in containing folder instead of exe folder

Issue

I have a dll which is some kind of plugin and I intend to deploy it as a package, the dll and all it’s dependencies (also dlls) in one package. The issue that I have is that the dll is checking for it’s dependencies in the exe folder instead of its own folder, its dependencies are next to it.

Is there a way to tell it where the dependencies are?

Edit:
In my case the plugin is loaded by QPluginLoader and the answers hinted that this is relevant as the loader decides where to look for dependencies.

Solution

As @Alex Reinking pointed out the loader is responsible for finding the dlls, in my case the loading was done by QPluginLoader and a solution was to set the current directory to the plugin directory as the loader looks in the current directory for dlls:

QDir pluginsDir(QLatin1String("../src/"));
QDir::setCurrent(pluginsDir.path());
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));

Answered By – Damir Porobic

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *