Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/plugin/qpluginloader.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qplatformdefs.h" | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #include "qplugin.h" | - | ||||||||||||||||||
37 | #include "qcoreapplication.h" | - | ||||||||||||||||||
38 | #include "qpluginloader.h" | - | ||||||||||||||||||
39 | #include <qfileinfo.h> | - | ||||||||||||||||||
40 | #include "qlibrary_p.h" | - | ||||||||||||||||||
41 | #include "qdebug.h" | - | ||||||||||||||||||
42 | #include "qdir.h" | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | /*! | - | ||||||||||||||||||
49 | \class QPluginLoader | - | ||||||||||||||||||
50 | \inmodule QtCore | - | ||||||||||||||||||
51 | \reentrant | - | ||||||||||||||||||
52 | \brief The QPluginLoader class loads a plugin at run-time. | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | - | |||||||||||||||||||
55 | \ingroup plugins | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | QPluginLoader provides access to a \l{How to Create Qt | - | ||||||||||||||||||
58 | Plugins}{Qt plugin}. A Qt plugin is stored in a shared library (a | - | ||||||||||||||||||
59 | DLL) and offers these benefits over shared libraries accessed | - | ||||||||||||||||||
60 | using QLibrary: | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | \list | - | ||||||||||||||||||
63 | \li QPluginLoader checks that a plugin is linked against the same | - | ||||||||||||||||||
64 | version of Qt as the application. | - | ||||||||||||||||||
65 | \li QPluginLoader provides direct access to a root component object | - | ||||||||||||||||||
66 | (instance()), instead of forcing you to resolve a C function manually. | - | ||||||||||||||||||
67 | \endlist | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | An instance of a QPluginLoader object operates on a single shared | - | ||||||||||||||||||
70 | library file, which we call a plugin. It provides access to the | - | ||||||||||||||||||
71 | functionality in the plugin in a platform-independent way. To | - | ||||||||||||||||||
72 | specify which plugin to load, either pass a file name in | - | ||||||||||||||||||
73 | the constructor or set it with setFileName(). | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | The most important functions are load() to dynamically load the | - | ||||||||||||||||||
76 | plugin file, isLoaded() to check whether loading was successful, | - | ||||||||||||||||||
77 | and instance() to access the root component in the plugin. The | - | ||||||||||||||||||
78 | instance() function implicitly tries to load the plugin if it has | - | ||||||||||||||||||
79 | not been loaded yet. Multiple instances of QPluginLoader can be | - | ||||||||||||||||||
80 | used to access the same physical plugin. | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | Once loaded, plugins remain in memory until all instances of | - | ||||||||||||||||||
83 | QPluginLoader has been unloaded, or until the application | - | ||||||||||||||||||
84 | terminates. You can attempt to unload a plugin using unload(), | - | ||||||||||||||||||
85 | but if other instances of QPluginLoader are using the same | - | ||||||||||||||||||
86 | library, the call will fail, and unloading will only happen when | - | ||||||||||||||||||
87 | every instance has called unload(). Right before the unloading | - | ||||||||||||||||||
88 | happen, the root component will also be deleted. | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | See \l{How to Create Qt Plugins} for more information about | - | ||||||||||||||||||
91 | how to make your application extensible through plugins. | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | Note that the QPluginLoader cannot be used if your application is | - | ||||||||||||||||||
94 | statically linked against Qt. In this case, you will also have to | - | ||||||||||||||||||
95 | link to plugins statically. You can use QLibrary if you need to | - | ||||||||||||||||||
96 | load dynamic libraries in a statically linked application. | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | \sa QLibrary, {Plug & Paint Example} | - | ||||||||||||||||||
99 | */ | - | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | /*! | - | ||||||||||||||||||
102 | \class QStaticPlugin | - | ||||||||||||||||||
103 | \inmodule QtCore | - | ||||||||||||||||||
104 | \since 5.2 | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | \brief QStaticPlugin is a struct containing a reference to a | - | ||||||||||||||||||
107 | static plugin instance together with its meta data. | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | \sa QPluginLoader, {How to Create Qt Plugins} | - | ||||||||||||||||||
110 | */ | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | /*! | - | ||||||||||||||||||
113 | \fn QObject *QStaticPlugin::instance() | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | Returns the plugin instance. | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | \sa QPluginLoader::staticInstances() | - | ||||||||||||||||||
118 | */ | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | /*! | - | ||||||||||||||||||
121 | \fn const char *QStaticPlugin::rawMetaData() | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | Returns the raw meta data for the plugin. | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | \sa metaData(), Q_PLUGIN_METADATA() | - | ||||||||||||||||||
126 | */ | - | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | /*! | - | ||||||||||||||||||
129 | Constructs a plugin loader with the given \a parent. | - | ||||||||||||||||||
130 | */ | - | ||||||||||||||||||
131 | QPluginLoader::QPluginLoader(QObject *parent) | - | ||||||||||||||||||
132 | : QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
133 | { | - | ||||||||||||||||||
134 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | /*! | - | ||||||||||||||||||
137 | Constructs a plugin loader with the given \a parent that will | - | ||||||||||||||||||
138 | load the plugin specified by \a fileName. | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | To be loadable, the file's suffix must be a valid suffix for a | - | ||||||||||||||||||
141 | loadable library in accordance with the platform, e.g. \c .so on | - | ||||||||||||||||||
142 | Unix, - \c .dylib on \macos and iOS, and \c .dll on Windows. The suffix | - | ||||||||||||||||||
143 | can be verified with QLibrary::isLibrary(). | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | \sa setFileName() | - | ||||||||||||||||||
146 | */ | - | ||||||||||||||||||
147 | QPluginLoader::QPluginLoader(const QString &fileName, QObject *parent) | - | ||||||||||||||||||
148 | : QObject(parent), d(0), did_load(false) | - | ||||||||||||||||||
149 | { | - | ||||||||||||||||||
150 | setFileName(fileName); | - | ||||||||||||||||||
151 | setLoadHints(QLibrary::PreventUnloadHint); | - | ||||||||||||||||||
152 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | /*! | - | ||||||||||||||||||
155 | Destroys the QPluginLoader object. | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | Unless unload() was called explicitly, the plugin stays in memory | - | ||||||||||||||||||
158 | until the application terminates. | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | \sa isLoaded(), unload() | - | ||||||||||||||||||
161 | */ | - | ||||||||||||||||||
162 | QPluginLoader::~QPluginLoader() | - | ||||||||||||||||||
163 | { | - | ||||||||||||||||||
164 | if (d)
| 1-27 | ||||||||||||||||||
165 | d->release(); executed 27 times by 2 tests: d->release(); Executed by:
| 27 | ||||||||||||||||||
166 | } executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | /*! | - | ||||||||||||||||||
169 | Returns the root component object of the plugin. The plugin is | - | ||||||||||||||||||
170 | loaded if necessary. The function returns 0 if the plugin could | - | ||||||||||||||||||
171 | not be loaded or if the root component object could not be | - | ||||||||||||||||||
172 | instantiated. | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | If the root component object was destroyed, calling this function | - | ||||||||||||||||||
175 | creates a new instance. | - | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | The root component, returned by this function, is not deleted when | - | ||||||||||||||||||
178 | the QPluginLoader is destroyed. If you want to ensure that the root | - | ||||||||||||||||||
179 | component is deleted, you should call unload() as soon you don't | - | ||||||||||||||||||
180 | need to access the core component anymore. When the library is | - | ||||||||||||||||||
181 | finally unloaded, the root component will automatically be deleted. | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | The component object is a QObject. Use qobject_cast() to access | - | ||||||||||||||||||
184 | interfaces you are interested in. | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | \sa load() | - | ||||||||||||||||||
187 | */ | - | ||||||||||||||||||
188 | QObject *QPluginLoader::instance() | - | ||||||||||||||||||
189 | { | - | ||||||||||||||||||
190 | if (!isLoaded() && !load())
| 1-16 | ||||||||||||||||||
191 | return 0; executed 4 times by 1 test: return 0; Executed by:
| 4 | ||||||||||||||||||
192 | if (!d->inst && d->instance)
| 0-9 | ||||||||||||||||||
193 | d->inst = d->instance(); executed 9 times by 2 tests: d->inst = d->instance(); Executed by:
| 9 | ||||||||||||||||||
194 | return d->inst.data(); executed 17 times by 2 tests: return d->inst.data(); Executed by:
| 17 | ||||||||||||||||||
195 | } | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | /*! | - | ||||||||||||||||||
198 | Returns the meta data for this plugin. The meta data is data specified | - | ||||||||||||||||||
199 | in a json format using the Q_PLUGIN_METADATA() macro when compiling | - | ||||||||||||||||||
200 | the plugin. | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | The meta data can be queried in a fast and inexpensive way without | - | ||||||||||||||||||
203 | actually loading the plugin. This makes it possible to e.g. store | - | ||||||||||||||||||
204 | capabilities of the plugin in there, and make the decision whether to | - | ||||||||||||||||||
205 | load the plugin dependent on this meta data. | - | ||||||||||||||||||
206 | */ | - | ||||||||||||||||||
207 | QJsonObject QPluginLoader::metaData() const | - | ||||||||||||||||||
208 | { | - | ||||||||||||||||||
209 | if (!d)
| 0 | ||||||||||||||||||
210 | return QJsonObject(); never executed: return QJsonObject(); | 0 | ||||||||||||||||||
211 | return d->metaData; never executed: return d->metaData; | 0 | ||||||||||||||||||
212 | } | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | /*! | - | ||||||||||||||||||
215 | Loads the plugin and returns \c true if the plugin was loaded | - | ||||||||||||||||||
216 | successfully; otherwise returns \c false. Since instance() always | - | ||||||||||||||||||
217 | calls this function before resolving any symbols it is not | - | ||||||||||||||||||
218 | necessary to call it explicitly. In some situations you might want | - | ||||||||||||||||||
219 | the plugin loaded in advance, in which case you would use this | - | ||||||||||||||||||
220 | function. | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | \sa unload() | - | ||||||||||||||||||
223 | */ | - | ||||||||||||||||||
224 | bool QPluginLoader::load() | - | ||||||||||||||||||
225 | { | - | ||||||||||||||||||
226 | if (!d || d->fileName.isEmpty())
| 2-27 | ||||||||||||||||||
227 | return false; executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||||||||
228 | if (did_load)
| 0-23 | ||||||||||||||||||
229 | return d->pHnd && d->instance; never executed: return d->pHnd && d->instance;
| 0 | ||||||||||||||||||
230 | if (!d->isPlugin())
| 11-12 | ||||||||||||||||||
231 | return false; executed 12 times by 1 test: return false; Executed by:
| 12 | ||||||||||||||||||
232 | did_load = true; | - | ||||||||||||||||||
233 | return d->loadPlugin(); executed 11 times by 2 tests: return d->loadPlugin(); Executed by:
| 11 | ||||||||||||||||||
234 | } | - | ||||||||||||||||||
235 | - | |||||||||||||||||||
236 | - | |||||||||||||||||||
237 | /*! | - | ||||||||||||||||||
238 | Unloads the plugin and returns \c true if the plugin could be | - | ||||||||||||||||||
239 | unloaded; otherwise returns \c false. | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | This happens automatically on application termination, so you | - | ||||||||||||||||||
242 | shouldn't normally need to call this function. | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | If other instances of QPluginLoader are using the same plugin, the | - | ||||||||||||||||||
245 | call will fail, and unloading will only happen when every instance | - | ||||||||||||||||||
246 | has called unload(). | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | Don't try to delete the root component. Instead rely on | - | ||||||||||||||||||
249 | that unload() will automatically delete it when needed. | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | \sa instance(), load() | - | ||||||||||||||||||
252 | */ | - | ||||||||||||||||||
253 | bool QPluginLoader::unload() | - | ||||||||||||||||||
254 | { | - | ||||||||||||||||||
255 | if (did_load) {
| 4-9 | ||||||||||||||||||
256 | did_load = false; | - | ||||||||||||||||||
257 | return d->unload(); executed 9 times by 1 test: return d->unload(); Executed by:
| 9 | ||||||||||||||||||
258 | } | - | ||||||||||||||||||
259 | if (d) // Ouch
| 1-3 | ||||||||||||||||||
260 | d->errorString = tr("The plugin was not loaded."); executed 3 times by 1 test: d->errorString = tr("The plugin was not loaded."); Executed by:
| 3 | ||||||||||||||||||
261 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||||||||
262 | } | - | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | /*! | - | ||||||||||||||||||
265 | Returns \c true if the plugin is loaded; otherwise returns \c false. | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | \sa load() | - | ||||||||||||||||||
268 | */ | - | ||||||||||||||||||
269 | bool QPluginLoader::isLoaded() const | - | ||||||||||||||||||
270 | { | - | ||||||||||||||||||
271 | return d && d->pHnd && d->instance; executed 22 times by 2 tests: return d && d->pHnd && d->instance; Executed by:
| 0-22 | ||||||||||||||||||
272 | } | - | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | #if defined(QT_SHARED) | - | ||||||||||||||||||
275 | static QString locatePlugin(const QString& fileName) | - | ||||||||||||||||||
276 | { | - | ||||||||||||||||||
277 | const bool isAbsolute = QDir::isAbsolutePath(fileName); | - | ||||||||||||||||||
278 | if (isAbsolute) {
| 3-24 | ||||||||||||||||||
279 | QFileInfo fi(fileName); | - | ||||||||||||||||||
280 | if (fi.isFile()) {
| 1-23 | ||||||||||||||||||
281 | return fi.canonicalFilePath(); executed 23 times by 2 tests: return fi.canonicalFilePath(); Executed by:
| 23 | ||||||||||||||||||
282 | } | - | ||||||||||||||||||
283 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
284 | QStringList prefixes = QLibraryPrivate::prefixes_sys(); | - | ||||||||||||||||||
285 | prefixes.prepend(QString()); | - | ||||||||||||||||||
286 | QStringList suffixes = QLibraryPrivate::suffixes_sys(QString()); | - | ||||||||||||||||||
287 | suffixes.prepend(QString()); | - | ||||||||||||||||||
288 | - | |||||||||||||||||||
289 | // Split up "subdir/filename" | - | ||||||||||||||||||
290 | const int slash = fileName.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||
291 | const QStringRef baseName = fileName.midRef(slash + 1); | - | ||||||||||||||||||
292 | const QStringRef basePath = isAbsolute ? QStringRef() : fileName.leftRef(slash + 1); // keep the '/'
| 1-3 | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | const bool debug = qt_debug_component(); | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | QStringList paths; | - | ||||||||||||||||||
297 | if (isAbsolute) {
| 1-3 | ||||||||||||||||||
298 | paths.append(fileName.left(slash)); // don't include the '/' | - | ||||||||||||||||||
299 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
300 | paths = QCoreApplication::libraryPaths(); | - | ||||||||||||||||||
301 | paths.prepend(QStringLiteral(".")); // search in current dir first executed 3 times by 1 test: return qstring_literal_temp; Executed by:
| 3 | ||||||||||||||||||
302 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | foreach (const QString &path, paths) { | - | ||||||||||||||||||
305 | foreach (const QString &prefix, prefixes) { | - | ||||||||||||||||||
306 | foreach (const QString &suffix, suffixes) { | - | ||||||||||||||||||
307 | const QString fn = path + QLatin1Char('/') + basePath + prefix + baseName + suffix; | - | ||||||||||||||||||
308 | if (debug)
| 0-36 | ||||||||||||||||||
309 | qDebug() << "Trying..." << fn; never executed: QMessageLogger(__FILE__, 309, __PRETTY_FUNCTION__).debug() << "Trying..." << fn; | 0 | ||||||||||||||||||
310 | if (QFileInfo(fn).isFile())
| 2-34 | ||||||||||||||||||
311 | return fn; executed 2 times by 1 test: return fn; Executed by:
| 2 | ||||||||||||||||||
312 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||
313 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||
314 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
315 | if (debug)
| 0-2 | ||||||||||||||||||
316 | qDebug() << fileName << "not found"; never executed: QMessageLogger(__FILE__, 316, __PRETTY_FUNCTION__).debug() << fileName << "not found"; | 0 | ||||||||||||||||||
317 | return QString(); executed 2 times by 1 test: return QString(); Executed by:
| 2 | ||||||||||||||||||
318 | } | - | ||||||||||||||||||
319 | #endif | - | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | /*! | - | ||||||||||||||||||
322 | \property QPluginLoader::fileName | - | ||||||||||||||||||
323 | \brief the file name of the plugin | - | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | We recommend omitting the file's suffix in the file name, since | - | ||||||||||||||||||
326 | QPluginLoader will automatically look for the file with the appropriate | - | ||||||||||||||||||
327 | suffix (see QLibrary::isLibrary()). | - | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | When loading the plugin, QPluginLoader searches in the current directory and | - | ||||||||||||||||||
330 | in all plugin locations specified by QCoreApplication::libraryPaths(), | - | ||||||||||||||||||
331 | unless the file name has an absolute path. After loading the plugin | - | ||||||||||||||||||
332 | successfully, fileName() returns the fully-qualified file name of | - | ||||||||||||||||||
333 | the plugin, including the full path to the plugin if one was given | - | ||||||||||||||||||
334 | in the constructor or passed to setFileName(). | - | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | If the file name does not exist, it will not be set. This property | - | ||||||||||||||||||
337 | will then contain an empty string. | - | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | By default, this property contains an empty string. | - | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | \sa load() | - | ||||||||||||||||||
342 | */ | - | ||||||||||||||||||
343 | void QPluginLoader::setFileName(const QString &fileName) | - | ||||||||||||||||||
344 | { | - | ||||||||||||||||||
345 | #if defined(QT_SHARED) | - | ||||||||||||||||||
346 | QLibrary::LoadHints lh = QLibrary::PreventUnloadHint; | - | ||||||||||||||||||
347 | if (d) {
| 1-26 | ||||||||||||||||||
348 | lh = d->loadHints(); | - | ||||||||||||||||||
349 | d->release(); | - | ||||||||||||||||||
350 | d = 0; | - | ||||||||||||||||||
351 | did_load = false; | - | ||||||||||||||||||
352 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | const QString fn = locatePlugin(fileName); | - | ||||||||||||||||||
355 | - | |||||||||||||||||||
356 | d = QLibraryPrivate::findOrCreate(fn, QString(), lh); | - | ||||||||||||||||||
357 | if (!fn.isEmpty())
| 2-25 | ||||||||||||||||||
358 | d->updatePluginState(); executed 25 times by 2 tests: d->updatePluginState(); Executed by:
| 25 | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | #else | - | ||||||||||||||||||
361 | if (qt_debug_component()) { | - | ||||||||||||||||||
362 | qWarning("Cannot load %s into a statically linked Qt library.", | - | ||||||||||||||||||
363 | (const char*)QFile::encodeName(fileName)); | - | ||||||||||||||||||
364 | } | - | ||||||||||||||||||
365 | Q_UNUSED(fileName); | - | ||||||||||||||||||
366 | #endif | - | ||||||||||||||||||
367 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | QString QPluginLoader::fileName() const | - | ||||||||||||||||||
370 | { | - | ||||||||||||||||||
371 | if (d)
| 0 | ||||||||||||||||||
372 | return d->fileName; never executed: return d->fileName; | 0 | ||||||||||||||||||
373 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
374 | } | - | ||||||||||||||||||
375 | - | |||||||||||||||||||
376 | /*! | - | ||||||||||||||||||
377 | \since 4.2 | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | Returns a text string with the description of the last error that occurred. | - | ||||||||||||||||||
380 | */ | - | ||||||||||||||||||
381 | QString QPluginLoader::errorString() const | - | ||||||||||||||||||
382 | { | - | ||||||||||||||||||
383 | return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; executed 26 times by 1 test: return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; Executed by:
| 3-26 | ||||||||||||||||||
384 | } | - | ||||||||||||||||||
385 | - | |||||||||||||||||||
386 | typedef QVector<QStaticPlugin> StaticPluginList; | - | ||||||||||||||||||
387 | Q_GLOBAL_STATIC(StaticPluginList, staticPluginList) executed 267 times by 245 tests: end of block Executed by:
executed 267 times by 245 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 40167 times by 146 tests: return &holder.value; Executed by:
| 0-40167 | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | /*! \since 4.4 | - | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | \property QPluginLoader::loadHints | - | ||||||||||||||||||
392 | \brief Give the load() function some hints on how it should behave. | - | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | You can give hints on how the symbols in the plugin are | - | ||||||||||||||||||
395 | resolved. By default since Qt 5.7, QLibrary::PreventUnloadHint is set. | - | ||||||||||||||||||
396 | - | |||||||||||||||||||
397 | See the documentation of QLibrary::loadHints for a complete | - | ||||||||||||||||||
398 | description of how this property works. | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | \sa QLibrary::loadHints | - | ||||||||||||||||||
401 | */ | - | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | void QPluginLoader::setLoadHints(QLibrary::LoadHints loadHints) | - | ||||||||||||||||||
404 | { | - | ||||||||||||||||||
405 | if (!d) {
| 1-22 | ||||||||||||||||||
406 | d = QLibraryPrivate::findOrCreate(QString()); // ugly, but we need a d-ptr | - | ||||||||||||||||||
407 | d->errorString.clear(); | - | ||||||||||||||||||
408 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
409 | d->setLoadHints(loadHints); | - | ||||||||||||||||||
410 | } executed 23 times by 2 tests: end of block Executed by:
| 23 | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | QLibrary::LoadHints QPluginLoader::loadHints() const | - | ||||||||||||||||||
413 | { | - | ||||||||||||||||||
414 | return d ? d->loadHints() : QLibrary::LoadHints(); executed 2 times by 1 test: return d ? d->loadHints() : QLibrary::LoadHints(); Executed by:
| 1-2 | ||||||||||||||||||
415 | } | - | ||||||||||||||||||
416 | - | |||||||||||||||||||
417 | /*! | - | ||||||||||||||||||
418 | \relates QPluginLoader | - | ||||||||||||||||||
419 | \since 5.0 | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | Registers the \a plugin specified with the plugin loader, and is used | - | ||||||||||||||||||
422 | by Q_IMPORT_PLUGIN(). | - | ||||||||||||||||||
423 | */ | - | ||||||||||||||||||
424 | void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin plugin) | - | ||||||||||||||||||
425 | { | - | ||||||||||||||||||
426 | staticPluginList()->append(plugin); | - | ||||||||||||||||||
427 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
428 | - | |||||||||||||||||||
429 | /*! | - | ||||||||||||||||||
430 | Returns a list of static plugin instances (root components) held | - | ||||||||||||||||||
431 | by the plugin loader. | - | ||||||||||||||||||
432 | \sa staticPlugins() | - | ||||||||||||||||||
433 | */ | - | ||||||||||||||||||
434 | QObjectList QPluginLoader::staticInstances() | - | ||||||||||||||||||
435 | { | - | ||||||||||||||||||
436 | QObjectList instances; | - | ||||||||||||||||||
437 | const StaticPluginList *plugins = staticPluginList(); | - | ||||||||||||||||||
438 | if (plugins) {
| 0 | ||||||||||||||||||
439 | const int numPlugins = plugins->size(); | - | ||||||||||||||||||
440 | instances.reserve(numPlugins); | - | ||||||||||||||||||
441 | for (int i = 0; i < numPlugins; ++i)
| 0 | ||||||||||||||||||
442 | instances += plugins->at(i).instance(); never executed: instances += plugins->at(i).instance(); | 0 | ||||||||||||||||||
443 | } never executed: end of block | 0 | ||||||||||||||||||
444 | return instances; never executed: return instances; | 0 | ||||||||||||||||||
445 | } | - | ||||||||||||||||||
446 | - | |||||||||||||||||||
447 | /*! | - | ||||||||||||||||||
448 | Returns a list of QStaticPlugins held by the plugin | - | ||||||||||||||||||
449 | loader. The function is similar to \l staticInstances() | - | ||||||||||||||||||
450 | with the addition that a QStaticPlugin also contains | - | ||||||||||||||||||
451 | meta data information. | - | ||||||||||||||||||
452 | \sa staticInstances() | - | ||||||||||||||||||
453 | */ | - | ||||||||||||||||||
454 | QVector<QStaticPlugin> QPluginLoader::staticPlugins() | - | ||||||||||||||||||
455 | { | - | ||||||||||||||||||
456 | StaticPluginList *plugins = staticPluginList(); | - | ||||||||||||||||||
457 | if (plugins)
| 0-40166 | ||||||||||||||||||
458 | return *plugins; executed 40166 times by 146 tests: return *plugins; Executed by:
| 40166 | ||||||||||||||||||
459 | return QVector<QStaticPlugin>(); never executed: return QVector<QStaticPlugin>(); | 0 | ||||||||||||||||||
460 | } | - | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | /*! | - | ||||||||||||||||||
463 | Returns a the meta data for the plugin as a QJsonObject. | - | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | \sa rawMetaData() | - | ||||||||||||||||||
466 | */ | - | ||||||||||||||||||
467 | QJsonObject QStaticPlugin::metaData() const | - | ||||||||||||||||||
468 | { | - | ||||||||||||||||||
469 | return QLibraryPrivate::fromRawMetaData(rawMetaData()).object(); executed 26 times by 1 test: return QLibraryPrivate::fromRawMetaData(rawMetaData()).object(); Executed by:
| 26 | ||||||||||||||||||
470 | } | - | ||||||||||||||||||
471 | - | |||||||||||||||||||
472 | QT_END_NAMESPACE | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | #endif // QT_NO_LIBRARY | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |