[Qt-interest] QPluginLoader not loading plugin just by name.
Brad Hards
bradh at frogmouth.net
Thu Sep 30 09:12:51 CEST 2010
On Thursday, September 30, 2010 05:10:20 pm Brad Hards wrote:
> 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).
[Sorry, slipped before completing this.]
>From http://doc.trolltech.com/latest/deployment-plugins.html :
The Plugin Directory
When the application is run, Qt will first treat the application's executable
directory as the pluginsbase. For example if the application is in C:\Program
Files\MyApp and has a style plugin, Qt will look in C:\Program
Files\MyApp\styles. (See QCoreApplication::applicationDirPath() for how to find
out where the application's executable is.) Qt will also look in the directory
specified by QLibraryInfo::location(QLibraryInfo::PluginsPath), which typically
is located in QTDIR/plugins (where QTDIR is the directory where Qt is
installed). If you want Qt to look in additional places you can add as many
paths as you need with calls to QCoreApplication::addLibraryPath(). And if you
want to set your own path or paths you can use
QCoreApplication::setLibraryPaths(). You can also use a qt.conf file to
override the hard-coded paths that are compiled into the Qt library. For more
information, see the Using qt.conf documentation. Yet another possibility is
to set the QT_PLUGIN_PATH environment variable before running the application.
If set, Qt will look for plugins in the paths (separated by the system path
separator) specified in the variable.
Brad
More information about the Qt-interest-old
mailing list