| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the documentation of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:FDL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in a | 
|---|
| 14 | ** written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Free Documentation License | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free | 
|---|
| 18 | ** Documentation License version 1.3 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file included in the packaging of this | 
|---|
| 20 | ** file. | 
|---|
| 21 | ** | 
|---|
| 22 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 23 | ** Nokia at qt-info@nokia.com. | 
|---|
| 24 | ** $QT_END_LICENSE$ | 
|---|
| 25 | ** | 
|---|
| 26 | ****************************************************************************/ | 
|---|
| 27 |  | 
|---|
| 28 | /*! | 
|---|
| 29 | \page deployment-plugins.html | 
|---|
| 30 | \title Deploying Plugins | 
|---|
| 31 | \brief A guide to plugins-specific aspects of deploying Qt and Qt Application | 
|---|
| 32 |  | 
|---|
| 33 | This document explains how to deploy plugin libraries that Qt or | 
|---|
| 34 | your application should load at runtime. If you use | 
|---|
| 35 | \l{How to Create Qt Plugins#Static Plugins}{static plugins}, then the | 
|---|
| 36 | plugin code is already part of your application executable, and no | 
|---|
| 37 | separate deployment steps are required. | 
|---|
| 38 |  | 
|---|
| 39 | \tableofcontents | 
|---|
| 40 |  | 
|---|
| 41 | \section1 The Plugin Directory | 
|---|
| 42 |  | 
|---|
| 43 | When the application is run, Qt will first treat the application's | 
|---|
| 44 | executable directory as the \c{pluginsbase}. For example if the | 
|---|
| 45 | application is in \c{C:\Program Files\MyApp} and has a style plugin, | 
|---|
| 46 | Qt will look in \c{C:\Program Files\MyApp\styles}. (See | 
|---|
| 47 | QCoreApplication::applicationDirPath() for how to find out where | 
|---|
| 48 | the application's executable is.) Qt will also look in the | 
|---|
| 49 | directory specified by | 
|---|
| 50 | QLibraryInfo::location(QLibraryInfo::PluginsPath), which typically | 
|---|
| 51 | is located in \c QTDIR/plugins (where \c QTDIR is the directory | 
|---|
| 52 | where Qt is installed). If you want Qt to look in additional | 
|---|
| 53 | places you can add as many paths as you need with calls to | 
|---|
| 54 | QCoreApplication::addLibraryPath(). And if you want to set your | 
|---|
| 55 | own path or paths you can use QCoreApplication::setLibraryPaths(). | 
|---|
| 56 | You can also use a \c qt.conf file to override the hard-coded | 
|---|
| 57 | paths that are compiled into the Qt library. For more information, | 
|---|
| 58 | see the \l {Using qt.conf} documentation. Yet another possibility | 
|---|
| 59 | is to set the \c QT_PLUGIN_PATH environment variable before running | 
|---|
| 60 | the application. If set, Qt will look for plugins in the | 
|---|
| 61 | paths (separated by the system path separator) specified in the variable. | 
|---|
| 62 |  | 
|---|
| 63 | \section1 Loading and Verifying Plugins Dynamically | 
|---|
| 64 |  | 
|---|
| 65 | When loading plugins, the Qt library does some sanity checking to | 
|---|
| 66 | determine whether or not the plugin can be loaded and used. This | 
|---|
| 67 | provides the ability to have multiple versions and configurations of | 
|---|
| 68 | the Qt library installed side by side. | 
|---|
| 69 |  | 
|---|
| 70 | \list | 
|---|
| 71 | \o Plugins linked with a Qt library that has a higher version number | 
|---|
| 72 | will not be loaded by a library with a lower version number. | 
|---|
| 73 |  | 
|---|
| 74 | \br | 
|---|
| 75 | \bold{Example:} Qt 4.3.0 will \e{not} load a plugin built with Qt 4.3.1. | 
|---|
| 76 |  | 
|---|
| 77 | \o Plugins linked with a Qt library that has a lower major version | 
|---|
| 78 | number will not be loaded by a library with a higher major version | 
|---|
| 79 | number. | 
|---|
| 80 |  | 
|---|
| 81 | \br | 
|---|
| 82 | \bold{Example:} Qt 4.3.1 will \e{not} load a plugin built with Qt 3.3.1. | 
|---|
| 83 | \br | 
|---|
| 84 | \bold{Example:} Qt 4.3.1 will load plugins built with Qt 4.3.0 and Qt 4.2.3. | 
|---|
| 85 |  | 
|---|
| 86 | \o The Qt library and all plugins are built using a \e {build | 
|---|
| 87 | key}. The build key in the Qt library is examined against the build | 
|---|
| 88 | key in the plugin, and if they match, the plugin is loaded. If the | 
|---|
| 89 | build keys do not match, then the Qt library refuses to load the | 
|---|
| 90 | plugin. | 
|---|
| 91 |  | 
|---|
| 92 | \br \bold{Rationale:} See the \l{#The Build Key}{The Build Key} section below. | 
|---|
| 93 | \endlist | 
|---|
| 94 |  | 
|---|
| 95 | When building plugins to extend an application, it is important to ensure | 
|---|
| 96 | that the plugin is configured in the same way as the application. This means | 
|---|
| 97 | that if the application was built in release mode, plugins should be built | 
|---|
| 98 | in release mode, too. | 
|---|
| 99 |  | 
|---|
| 100 | If you configure Qt to be built in both debug and release modes, | 
|---|
| 101 | but only build applications in release mode, you need to ensure that your | 
|---|
| 102 | plugins are also built in release mode. By default, if a debug build of Qt is | 
|---|
| 103 | available, plugins will \e only be built in debug mode. To force the | 
|---|
| 104 | plugins to be built in release mode, add the following line to the plugin's | 
|---|
| 105 | project file: | 
|---|
| 106 |  | 
|---|
| 107 | \snippet doc/src/snippets/code/doc_src_plugins-howto.qdoc 3 | 
|---|
| 108 |  | 
|---|
| 109 | This will ensure that the plugin is compatible with the version of the library | 
|---|
| 110 | used in the application. | 
|---|
| 111 |  | 
|---|
| 112 | \section2 The Build Key | 
|---|
| 113 |  | 
|---|
| 114 | When loading plugins, Qt checks the build key of each plugin against its | 
|---|
| 115 | own configuration to ensure that only compatible plugins are loaded; any | 
|---|
| 116 | plugins that are configured differently are not loaded. | 
|---|
| 117 |  | 
|---|
| 118 | The build key contains the following information: | 
|---|
| 119 | \list | 
|---|
| 120 | \o Architecture, operating system and compiler. | 
|---|
| 121 |  | 
|---|
| 122 | \e {Rationale:} | 
|---|
| 123 | In cases where different versions of the same compiler do not | 
|---|
| 124 | produce binary compatible code, the version of the compiler is | 
|---|
| 125 | also present in the build key. | 
|---|
| 126 |  | 
|---|
| 127 | \o Configuration of the Qt library. The configuration is a list | 
|---|
| 128 | of the missing features that affect the available API in the | 
|---|
| 129 | library. | 
|---|
| 130 |  | 
|---|
| 131 | \e {Rationale:} | 
|---|
| 132 | Two different configurations of the same version of | 
|---|
| 133 | the Qt library are not binary compatible. The Qt library that | 
|---|
| 134 | loads the plugin uses the list of (missing) features to | 
|---|
| 135 | determine if the plugin is binary compatible. | 
|---|
| 136 |  | 
|---|
| 137 | \e {Note:} There are cases where a plugin can use features that are | 
|---|
| 138 | available in two different configurations. However, the | 
|---|
| 139 | developer writing plugins would need to know which features are | 
|---|
| 140 | in use, both in their plugin and internally by the utility | 
|---|
| 141 | classes in Qt. The Qt library would require complex feature | 
|---|
| 142 | and dependency queries and verification when loading plugins. | 
|---|
| 143 | Requiring this would place an unnecessary burden on the developer, and | 
|---|
| 144 | increase the overhead of loading a plugin. To reduce both | 
|---|
| 145 | development time and application runtime costs, a simple string | 
|---|
| 146 | comparision of the build keys is used. | 
|---|
| 147 |  | 
|---|
| 148 | \o Optionally, an extra string may be specified on the configure | 
|---|
| 149 | script command line. | 
|---|
| 150 |  | 
|---|
| 151 | \e {Rationale:} | 
|---|
| 152 | When distributing binaries of the Qt library with an | 
|---|
| 153 | application, this provides a way for developers to write | 
|---|
| 154 | plugins that can only be loaded by the library with which the | 
|---|
| 155 | plugins were linked. | 
|---|
| 156 | \endlist | 
|---|
| 157 |  | 
|---|
| 158 | For debugging purposes, it is possible to override the run-time build key | 
|---|
| 159 | checks by configuring Qt with the \c QT_NO_PLUGIN_CHECK preprocessor macro | 
|---|
| 160 | defined. | 
|---|
| 161 |  | 
|---|
| 162 | \section1 The Plugin Cache | 
|---|
| 163 |  | 
|---|
| 164 | In order to speed up loading and validation of plugins, some of | 
|---|
| 165 | the information that is collected when plugins are loaded is cached | 
|---|
| 166 | through QSettings. This includes information about whether or not | 
|---|
| 167 | a plugin was successfully loaded, so that subsequent load operations | 
|---|
| 168 | don't try to load an invalid plugin. However, if the "last modified" | 
|---|
| 169 | timestamp of a plugin has changed, the plugin's cache entry is | 
|---|
| 170 | invalidated and the plugin is reloaded regardless of the values in | 
|---|
| 171 | the cache entry, and the cache entry itself is updated with the new | 
|---|
| 172 | result. | 
|---|
| 173 |  | 
|---|
| 174 | This also means that the timestamp must be updated each time the | 
|---|
| 175 | plugin or any dependent resources (such as a shared library) is | 
|---|
| 176 | updated, since the dependent resources might influence the result | 
|---|
| 177 | of loading a plugin. | 
|---|
| 178 |  | 
|---|
| 179 | Sometimes, when developing plugins, it is necessary to remove entries | 
|---|
| 180 | from the plugin cache. Since Qt uses QSettings to manage the plugin | 
|---|
| 181 | cache, the locations of plugins are platform-dependent; see | 
|---|
| 182 | \l{QSettings#Platform-Specific Notes}{the QSettings documentation} | 
|---|
| 183 | for more information about each platform. | 
|---|
| 184 |  | 
|---|
| 185 | For example, on Windows the entries are stored in the registry, and the | 
|---|
| 186 | paths for each plugin will typically begin with either of these two strings: | 
|---|
| 187 |  | 
|---|
| 188 | \snippet doc/src/snippets/code/doc_src_plugins-howto.qdoc 6 | 
|---|
| 189 |  | 
|---|
| 190 | \section1 Debugging Plugins | 
|---|
| 191 |  | 
|---|
| 192 | There are a number of issues that may prevent correctly-written plugins from | 
|---|
| 193 | working with the applications that are designed to use them. Many of these | 
|---|
| 194 | are related to differences in the way that plugins and applications have been | 
|---|
| 195 | built, often arising from separate build systems and processes. | 
|---|
| 196 |  | 
|---|
| 197 | The following table contains descriptions of the common causes of problems | 
|---|
| 198 | developers experience when creating plugins: | 
|---|
| 199 |  | 
|---|
| 200 | \table | 
|---|
| 201 | \header \o Problem \o Cause \o Solution | 
|---|
| 202 | \row \o Plugins sliently fail to load even when opened directly by the | 
|---|
| 203 | application. \QD shows the plugin libraries in its | 
|---|
| 204 | \gui{Help|About Plugins} dialog, but no plugins are listed under each | 
|---|
| 205 | of them. | 
|---|
| 206 | \o The application and its plugins are built in different modes. | 
|---|
| 207 | \o Either share the same build information or build the plugins in both | 
|---|
| 208 | debug and release modes by appending the \c debug_and_release to | 
|---|
| 209 | the \l{qmake Variable Reference#CONFIG}{CONFIG} variable in each of | 
|---|
| 210 | their project files. | 
|---|
| 211 | \row \o A valid plugin that replaces an invalid (or broken) plugin fails to load. | 
|---|
| 212 | \o The entry for the plugin in the plugin cache indicates that the original | 
|---|
| 213 | plugin could not be loaded, causing Qt to ignore the replacement. | 
|---|
| 214 | \o Either ensure that the plugin's timestamp is updated, or delete the | 
|---|
| 215 | entry in the \l{#The Plugin Cache}{plugin cache}. | 
|---|
| 216 | \endtable | 
|---|
| 217 |  | 
|---|
| 218 | You can also use the \c QT_DEBUG_PLUGINS environment variable to obtain | 
|---|
| 219 | diagnostic information from Qt about each plugin it tries to load. Set this | 
|---|
| 220 | variable to a non-zero value in the environment from which your application is | 
|---|
| 221 | launched. | 
|---|
| 222 | */ | 
|---|