gregseth
gregseth

Reputation: 13428

Check for dependency of a Qt plugin at runtime

Here's what I have: My application is statically compiled with Qt 4.5. I'm using the qsqloci plugin (linked statically), which loads the oracle libraries dynamically (oci.dll, ...).

I'd like to be able to check for the presence of the oracle DLLs and according to the result use the plugin features or not.

And the questions:

Upvotes: 3

Views: 1819

Answers (1)

Silas Parker
Silas Parker

Reputation: 8157

You can check if a DLL is available by using QLibrary.

After the library had loaded, instead of starting to use QLibrary::resolve, you would load your plugin.

QLibrary lib("oci"); // QLibrary will try the platform's library suffix
if (! lib.load()) {
  qDebug() << "Library load error:" << lib.errorString();
  return;
}
// load plugin

You can't use QPluginLoader to load the plugin because you are statically linking, but you should be able to use QLibrary.

The manual states:

Note that the QPluginLoader cannot be used if your application is statically linked against Qt. In this case, you will also have to link to plugins statically. You can use QLibrary if you need to load dynamic libraries in a statically linked application.

Upvotes: 4

Related Questions