Qt Manual has specifically introduced the problem of deploying Plugins. Six months ago QT plug-in learning (a) also simple collation of a bit of path-related issues.
However, has not been clear: image plugin, codec plug-in, database plug-in ... Exactly how it was loaded. Skim
If we need to open or save a JPG-formatted picture, then we need to load the JPG plugin. Where the program goes to find plugins:
The answer to the surface:
$QTDIR/plugins/imageformats/
you_app_path/imageformats/
Note: If you just want the plugin to work and not be interested in the other, create a imageformats directory directly in the directory where your application is located and put the plugin in. Other plugins and so on, create the appropriate subdirectories, respectively. Real Answers
Qstringlist qcoreapplication::librarypaths ()
For the picture plug-in, the program iterates through the list of strings, connecting each string to the/imageformats, and then attempting to load the dynamic library under those paths in turn.
Code of Attraction (with abridged)
void Qfactoryloader::update ()
{
qstringlist paths = Qcoreapplication::librarypaths ();
for (int i = 0; i < Paths.count (); ++i) {
const QString &plugindir = paths.at (i);
QString Path = Plugindir + d->suffix;
Qstringlist plugins = qdir (path). Entrylist (qdir::files);
Qlibraryprivate *library = 0;
for (int j = 0; J < Plugins.count (); ++j) {
QString fileName = qdir::cleanpath (path + qlatin1char ('/') + plugins.at (j));
Library = qlibraryprivate::findorcreate (Qfileinfo (fileName). Canonicalfilepath ());
}
}
...
For the picture plug-in, D->suffix is/imageformats, which is accomplished by a static loader () function that returns a value of qfactoryloader*:
Q_global_static_with_args (Qfactoryloader, loader,
(QIMAGEIOHANDLERFACTORYINTERFACE_IID, qlatin1string ("/ Imageformats ")))
It doesn't feel right.
It doesn't seem right in front of me. Not only with our superficial answers, but also in manual and in other people's articles that there are many things, such as:
Qlibraryinfo::location (qlibraryinfo::P luginspath):/qt/etc/qt.conf qt_plugin_path ... Qcoreapplication::addlibrarypath () qcoreapplication::setlibrarypaths ()
In addition to the following two direct correlations, other librarypaths seems to have little contact. How can you say it's only about Qcoreapplication::librarypaths () ....
Try to speak with the facts ... qcoreapplication::librarypaths () Create an empty qstringlist
Join the Qlibraryinfo::location (qlibraryinfo::P luginspath) path
Make sure to add the path Qcoreapplication::applicationfilepath () of the application itself
Joins the path specified by the QT_PLUGIN_PATH environment variable in sequence
Source:
Qstringlist qcoreapplication::librarypaths () {if (!coreappdata ()->app_libpaths) {qstringlist *app_libpath
s = Coreappdata ()->app_libpaths = new Qstringlist;
QString installpathplugins = qlibraryinfo::location (qlibraryinfo::P luginspath);
if (qfile::exists (installpathplugins)) {//Make sure we convert from backslashes to slashes.
Installpathplugins = Qdir (installpathplugins). Canonicalpath ();
if (!app_libpaths->contains (installpathplugins)) app_libpaths->append (installpathplugins); }//If qcoreapplication is not yet instantiated,//Make sure we add the application path when we Constru
CT the qcoreapplication if (self) self->d_func ()->appendapplicationpathtolibrarypaths ();
Const Qbytearray libpathenv = qgetenv ("Qt_plugin_path");
if (!libpathenv.isempty ()) {#if defined (Q_os_win) | | defined (q_os_symbian) Qlatin1char pathsep (';');#else Qlatin1char pathsep (': ');
#endif qstringlist paths = qstring::fromlatin1 (libpathenv). Split (Pathsep, Qstring::skipemptyparts); for (Qstringlist::const_iterator it = Paths.constbegin (); It! = Paths.constend (); ++it) {QString Canon
Icalpath = Qdir (*it). Canonicalpath ();
if (!canonicalpath.isempty () &&!app_libpaths->contains (Canonicalpath)) {
App_libpaths->append (Canonicalpath); }
}
}
...
It seems much more comfortable now, but Qlibraryinfo::location (qlibraryinfo::P luginspath). qlibraryinfo::location (qlibraryinfo::P luginspath)
It is affected in two ways: if there is a qualifying qt.conf file, the contents of the file will be used if there is no such qt.conf file that will be used to compile QT when writing dead content
First look at the latter: Configure
The first step in compiling QT is configure, which will generate Qconfig.h and qconfig.cpp two files in the Src/corelib/global directory.
Open the Qconfig.cpp file (you can see something like this):
static const char Qt_configure_installation [one +] = "qt_instdate=2011-06-08";
static const char QT_CONFIGURE_PREFIX_PATH_STR [+] = "Qt_prfxpath=e://qt5//qtbase-build";
static const char QT_CONFIGURE_BINARIES_PATH_STR [+] = "Qt_binspath=e://qt5//qtbase-build//bin";
static const char QT_CONFIGURE_PLUGINS_PATH_STR [+] = "Qt_plugpath=e://qt5//qtbase-build//plugins";
#define Qt_configure_binaries_path Qt_configure_binaries_path_str +;
#define Qt_configure_plugins_path Qt_configure_plugins_path_str + 12;
Note: Macro Qt_configure_plugins_path points to "qt_plugpath=e://qt5//qtbase-build//plugins"; qt.conf
First look at the resource file has no:/qt/etc/qt.conf does not exist check if the application is located under the path of the qt.conf file is found to return the corresponding qsettings, otherwise return 0
Qsettings *qlibraryinfoprivate::findconfiguration ()
{
QString qtconfig = qlatin1string (":/qt/etc/qt.conf") ;
if (! Qfile::exists (qtconfig) && qcoreapplication::instance ()) {
{
qdir pwd (qcoreapplication:: Applicationdirpath ());
Qtconfig = Pwd.filepath (qlatin1string ("qt.conf"));
}
}
if (qfile::exists (qtconfig))
return new Qsettings (Qtconfig, Qsettings::iniformat);
return 0;
}
merged
Direct patch code snippet, not explained
QString
qlibraryinfo::location (librarylocation Loc)
{
QString ret;
if (! Qlibraryinfoprivate::configuration ()) {
const char *path = 0;
Switch (Loc) {
...
Case Pluginspath:
path = Qt_configure_plugins_path;
break;
...
Default: Break
;
}
if (path)
ret = qstring::fromlocal8bit (path);
} else {
QString key;
QString DefaultValue;
Switch (Loc) {case
Pluginspath:
key = qlatin1string ("Plugins");
DefaultValue = qlatin1string ("plugins");
break;
...
Cache
In order to speed up the load and check of the plugin, some plug-in information will be saved with qsettings.
Take a look at the code snippet:
Qfactoryloader::update ()
{
qsettings settings (Qsettings::userscope, qlatin1string ("Trolltech"));
QString regkey = qstring::fromlatin1 ("Qt Factory Cache%1.%2/%3:/%4")
. Arg (qt_version & 0xff0000) >> 16) C4/>.arg ((Qt_version & 0xff00) >> 8)
. Arg (qlatin1string (D->IID))
. Arg (fileName);
Qstringlist reg;
Reg << library->lastmodified;
reg + = keys;
Settings.setvalue (RegKey, Reg);
And
BOOL Qlibraryprivate::isplugin (qsettings *settings)
{
...
QString regkey = qstring::fromlatin1 ("Qt Plugin Cache%1.%2.%3/%4")
. Arg (qt_version & 0xff0000) >> 16) C15/>.arg ((Qt_version & 0xff00) >> 8)
. Arg (qlibrary_as_debug? Qlatin1string ("Debug"): Qlatin1string ("false"))
. Arg (fileName);
...
Look at the registry content under Windows:
HKCU/SOFTWARE/TROLLTECH/ORGANIZATIONDEFAULTS/QT Factory Cache 4.7/ Com.trolltech.qt.qimageiohandlerfactoryinterface:/f:/qt4/plugins/imageformats/qtjpeg4.dll = 2010-09-29T14:40:30 JPEG jpg
Linux under ~/.config/trolltech.conf
[Qt Factory Cache 4.7]
Com.trolltech.qt.qimageiohandlerfactoryinterface:/home/qt4/plugins/imageformats/qtjpeg4.dll = 2011-04-22T17 : 21:23 jpeg jpg
Reference
Http://doc.qt.nokia.com/latest/deployment-plugins.html
Http://doc.qt.nokia.com/latest/qt-conf.html
Http://hi.baidu.com/cyclone/blog/item/0fc7462376f208429822ed1d.html