summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r--src/corelib/plugin/qfactoryloader.cpp29
-rw-r--r--src/corelib/plugin/qlibrary.cpp16
-rw-r--r--src/corelib/plugin/qlibrary.h3
-rw-r--r--src/corelib/plugin/qlibrary_unix.cpp12
-rw-r--r--src/corelib/plugin/qplugin.qdoc10
-rw-r--r--src/corelib/plugin/qpluginloader.h2
-rw-r--r--src/corelib/plugin/quuid.cpp6
7 files changed, 53 insertions, 25 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp
index 3f192ea477..fc9e94037f 100644
--- a/src/corelib/plugin/qfactoryloader.cpp
+++ b/src/corelib/plugin/qfactoryloader.cpp
@@ -326,20 +326,29 @@ QObject *QFactoryLoader::instance(const QString &key) const
QObject *QFactoryLoader::instance(int index) const
{
Q_D(const QFactoryLoader);
- if (index < 0 || index >= d->libraryList.size())
+ if (index < 0)
return 0;
- QLibraryPrivate *library = d->libraryList.at(index);
- if (library->instance || library->loadPlugin()) {
- if (!library->inst)
- library->inst = library->instance();
- QObject *obj = library->inst.data();
- if (obj) {
- if (!obj->parent())
- obj->moveToThread(QCoreApplicationPrivate::mainThread());
- return obj;
+ if (index < d->libraryList.size()) {
+ QLibraryPrivate *library = d->libraryList.at(index);
+ if (library->instance || library->loadPlugin()) {
+ if (!library->inst)
+ library->inst = library->instance();
+ QObject *obj = library->inst.data();
+ if (obj) {
+ if (!obj->parent())
+ obj->moveToThread(QCoreApplicationPrivate::mainThread());
+ return obj;
+ }
}
+ return 0;
}
+
+ index -= d->libraryList.size();
+ QVector<QStaticPlugin> staticPlugins = QLibraryPrivate::staticPlugins();
+ if (index < staticPlugins.size())
+ return staticPlugins.at(index).instance();
+
return 0;
}
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 216e6e1e7c..a704b8f02d 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -127,7 +127,7 @@ static QBasicMutex qt_library_mutex;
symbol is not defined, the function pointer will be 0 and won't be
called.
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 0
+ \snippet code/src_corelib_plugin_qlibrary.cpp 0
The symbol must be exported as a C function from the library for
resolve() to work. This means that the function must be wrapped in
@@ -138,7 +138,7 @@ static QBasicMutex qt_library_mutex;
use if you just want to call a function in a library without
explicitly loading the library first:
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 1
+ \snippet code/src_corelib_plugin_qlibrary.cpp 1
\sa QPluginLoader
*/
@@ -163,6 +163,10 @@ static QBasicMutex qt_library_mutex;
If this hint is given, the filename of the library consists of
a path, which is a reference to an archive file, followed by
a reference to the archive member.
+ \value PreventUnloadHint
+ Prevents the library from being unloaded from the address space if close()
+ is called. The library's static variables are not reinitialized if open()
+ is called at a later time.
\sa loadHints
*/
@@ -1118,7 +1122,7 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver
not be resolved or if the library could not be loaded.
Example:
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 2
+ \snippet code/src_corelib_plugin_qlibrary.cpp 2
The symbol must be exported as a C function from the library. This
means that the function must be wrapped in an \c{extern "C"} if
@@ -1126,11 +1130,11 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver
also explicitly export the function from the DLL using the
\c{__declspec(dllexport)} compiler directive, for example:
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 3
+ \snippet code/src_corelib_plugin_qlibrary.cpp 3
with \c MY_EXPORT defined as
- \snippet doc/src/snippets/code/src_corelib_plugin_qlibrary.cpp 4
+ \snippet code/src_corelib_plugin_qlibrary.cpp 4
*/
QFunctionPointer QLibrary::resolve(const char *symbol)
{
@@ -1230,6 +1234,8 @@ QString QLibrary::errorString() const
to the library \c shr_64.o in the archive file named \c libGL.a. This
is only supported on the AIX platform.
+ Setting PreventUnloadHint will only apply on Unix platforms.
+
The interpretation of the load hints is platform dependent, and if
you use it you are probably making some assumptions on which platform
you are compiling for, so use them only if you understand the consequences
diff --git a/src/corelib/plugin/qlibrary.h b/src/corelib/plugin/qlibrary.h
index f373ad06b6..80e6fd3d4c 100644
--- a/src/corelib/plugin/qlibrary.h
+++ b/src/corelib/plugin/qlibrary.h
@@ -68,7 +68,8 @@ public:
enum LoadHint {
ResolveAllSymbolsHint = 0x01,
ExportExternalSymbolsHint = 0x02,
- LoadArchiveMemberHint = 0x04
+ LoadArchiveMemberHint = 0x04,
+ PreventUnloadHint = 0x08
};
Q_DECLARE_FLAGS(LoadHints, LoadHint)
diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp
index cb81440c7e..0ad7a87c97 100644
--- a/src/corelib/plugin/qlibrary_unix.cpp
+++ b/src/corelib/plugin/qlibrary_unix.cpp
@@ -167,6 +167,18 @@ bool QLibraryPrivate::load_sys()
dlFlags |= RTLD_LOCAL;
}
#endif
+
+ // Provide access to RTLD_NODELETE flag on Unix
+ // From GNU documentation on RTLD_NODELETE:
+ // Do not unload the library during dlclose(). Consequently, the
+ // library's specific static variables are not reinitialized if the
+ // library is reloaded with dlopen() at a later time.
+#ifdef RTLD_NODELETE
+ if (loadHints & QLibrary::PreventUnloadHint) {
+ dlFlags |= RTLD_NODELETE;
+ }
+#endif
+
#if defined(Q_OS_AIX) // Not sure if any other platform actually support this thing.
if (loadHints & QLibrary::LoadArchiveMemberHint) {
dlFlags |= RTLD_MEMBER;
diff --git a/src/corelib/plugin/qplugin.qdoc b/src/corelib/plugin/qplugin.qdoc
index 77069e6dfd..001b0d5932 100644
--- a/src/corelib/plugin/qplugin.qdoc
+++ b/src/corelib/plugin/qplugin.qdoc
@@ -42,7 +42,7 @@
to the interface class called \a ClassName. The \a Identifier must
be unique. For example:
- \snippet examples/tools/plugandpaint/interfaces.h 3
+ \snippet tools/plugandpaint/interfaces.h 3
This macro is normally used right after the class definition for
\a ClassName, in a header file. See the
@@ -51,7 +51,7 @@
If you want to use Q_DECLARE_INTERFACE with interface classes
declared in a namespace then you have to make sure the Q_DECLARE_INTERFACE
is not inside a namespace though. For example:
- \snippet doc/src/snippets/code/doc_src_qplugin.cpp 0
+ \snippet code/doc_src_qplugin.cpp 0
\sa Q_INTERFACES(), Q_EXPORT_PLUGIN2(), {How to Create Qt Plugins}
*/
@@ -82,7 +82,7 @@
Example:
- \snippet doc/src/snippets/code/doc_src_qplugin.cpp 1
+ \snippet code/doc_src_qplugin.cpp 1
See the \l{tools/plugandpaint}{Plug & Paint} example for details.
@@ -102,14 +102,14 @@
Example:
- \snippet doc/src/snippets/code/doc_src_qplugin.cpp 2
+ \snippet code/doc_src_qplugin.cpp 2
Static plugins must also be included by the linker when your
application is built. For Qt's predefined plugins,
you can use the \c QTPLUGIN to add
the required plugins to your build. For example:
- \snippet doc/src/snippets/code/doc_src_qplugin.pro 3
+ \snippet code/doc_src_qplugin.pro 3
\sa {Static Plugins}, {How to Create Qt Plugins}, {Using qmake}
*/
diff --git a/src/corelib/plugin/qpluginloader.h b/src/corelib/plugin/qpluginloader.h
index 6ca1892fa9..0e62d3660b 100644
--- a/src/corelib/plugin/qpluginloader.h
+++ b/src/corelib/plugin/qpluginloader.h
@@ -69,7 +69,7 @@ public:
QObject *instance();
- QT_DEPRECATED static QObjectList staticInstances();
+ static QObjectList staticInstances();
bool load();
bool unload();
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 26032323e0..b1805afd53 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -337,7 +337,7 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto
b8.
Example:
- \snippet doc/src/snippets/code/src_corelib_plugin_quuid.cpp 0
+ \snippet code/src_corelib_plugin_quuid.cpp 0
*/
#ifndef QT_NO_QUUID_STRING
@@ -425,7 +425,7 @@ QUuid::QUuid(const QByteArray &text)
/*!
\since 5.0
- \fn QUuid::createUuidV3()
+ \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData);
This functions returns a new UUID with variant QUuid::DCE and version QUuid::MD5.
\a ns is the namespace and \a name is the name as described by RFC 4122.
@@ -435,7 +435,7 @@ QUuid::QUuid(const QByteArray &text)
/*!
\since 5.0
- \fn QUuid::createUuidV5()
+ \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData);
This functions returns a new UUID with variant QUuid::DCE and version QUuid::SHA1.
\a ns is the namespace and \a name is the name as described by RFC 4122.