[Qt-interest] QPluginLoader not loading plugin just by name.

Brad Hards bradh at frogmouth.net
Thu Sep 30 09:10:20 CEST 2010


On Thursday, September 30, 2010 01:58:41 am Pritam Ghanghas wrote:
> Say I have a plugin named "myplugin.so" in some dir on my filessystem
> and that dir is added to LD_LIBRARY_PATH.
> 
> Shouldn't the following code work?
> 
> QPluginLoader loader("myplugin.so");
> loader.instance();
> 
> Though the documentation doesn't say anything like that but isn't it a
> desirable feature. QLibrary does this.
>From http://doc.trolltech.com/latest/plugins-howto.html :
Locating Plugins

Qt applications automatically know which plugins are available, because 
plugins are stored in the standard plugin subdirectories. Because of this 
applications don't require any code to find and load plugins, since Qt handles 
them automatically.

During development, the directory for plugins is QTDIR/plugins (where QTDIR is 
the directory where Qt is installed), with each type of plugin in a 
subdirectory for that type, e.g. styles. If you want your applications to use 
plugins and you don't want to use the standard plugins path, have your 
installation process determine the path you want to use for the plugins, and 
save the path, e.g. using QSettings, for the application to read when it runs. 
The application can then call QCoreApplication::addLibraryPath() with this 
path and your plugins will be available to the application. Note that the final 
part of the path (e.g., styles) cannot be changed.

If you want the plugin to be loadable then one approach is to create a 
subdirectory under the application and place the plugin in that directory. If 
you distribute any of the plugins that come with Qt (the ones located in the 
plugins directory), you must copy the sub-directory under plugins where the 
plugin is located to your applications root folder (i.e., do not include the 
plugins directory).




More information about the Qt-interest-old mailing list