From 5bbbea4c83149d6920cff2991fc2458c49a1004e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 26 Apr 2016 14:43:01 +0200 Subject: normalize structure of plugandpaint example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit as in other examples which come with plugins, use an additional hierarchy level which contains the app and plugin subdirs. Change-Id: I2487755967aa3474c337c8c8af10be49627b63d0 Reviewed-by: Topi Reiniƶ --- src/corelib/plugin/qplugin.qdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/plugin') diff --git a/src/corelib/plugin/qplugin.qdoc b/src/corelib/plugin/qplugin.qdoc index 1b394c4174..09eed5a1e6 100644 --- a/src/corelib/plugin/qplugin.qdoc +++ b/src/corelib/plugin/qplugin.qdoc @@ -44,11 +44,11 @@ to the interface class called \a ClassName. The \a Identifier must be unique. For example: - \snippet plugandpaint/interfaces.h 3 + \snippet plugandpaint/app/interfaces.h 3 This macro is normally used right after the class definition for \a ClassName, in a header file. See the - \l{tools/plugandpaint}{Plug & Paint} example for details. + \l{tools/plugandpaint/app}{Plug & Paint} example for details. 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 @@ -76,7 +76,7 @@ \snippet code/doc_src_qplugin.cpp 1 - See the \l{tools/plugandpaint}{Plug & Paint} example for details. + See the \l{tools/plugandpaint/app}{Plug & Paint} example for details. Note that the class this macro appears on must be default-constructible. -- cgit v1.2.3 From a63ca3fa106f4b0f9776bf2004661ef6dec2c0c6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 28 Apr 2016 14:09:32 -0700 Subject: Implement QLibrary::PreventUnloadHint for Windows It's interesting that the HMODULE/HINSTANCE pointer points to something in the actual module that got loaded, so we can use its value as "address of something in the module" for GetModuleHandleEx. The "PIN" flag tells the Windows DLL loader to never unload. Change-Id: Ifea6e497f11a461db432ffff1449a2169eb6293e Reviewed-by: Friedemann Kleint Reviewed-by: Kai Koehne Reviewed-by: Joerg Bornemann --- src/corelib/plugin/qlibrary.cpp | 2 -- src/corelib/plugin/qlibrary_win.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/corelib/plugin') diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 9babfa4d91..ff04116705 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -1096,8 +1096,6 @@ 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_win.cpp b/src/corelib/plugin/qlibrary_win.cpp index deec54db0a..95e5afa837 100644 --- a/src/corelib/plugin/qlibrary_win.cpp +++ b/src/corelib/plugin/qlibrary_win.cpp @@ -148,6 +148,16 @@ bool QLibraryPrivate::load_sys() else qualifiedFileName = dir.filePath(moduleFileName); #endif // !Q_OS_WINRT + + if (loadHints() & QLibrary::PreventUnloadHint) { + // prevent the unloading of this component + HMODULE hmod; + bool ok = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN | + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + reinterpret_cast(pHnd), + &hmod); + Q_ASSERT(!ok || hmod == pHnd); + } } return (pHnd != 0); } -- cgit v1.2.3 From 4c06592ad80dc55420c4b9efebae2a39f4ad5542 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 10 May 2016 14:09:59 +0200 Subject: Fix build on WinRT a63ca3fa106f4b0f9776bf2004661ef6dec2c0c6 caused a build breakage for WinRT as GetModuleHandleEx does not exist on that platform. Change-Id: I143d9cad5f32d98a4d86292dfa73f94a4acdf305 Reviewed-by: Simon Hausmann --- src/corelib/plugin/qlibrary_win.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib/plugin') diff --git a/src/corelib/plugin/qlibrary_win.cpp b/src/corelib/plugin/qlibrary_win.cpp index 95e5afa837..46fbba151c 100644 --- a/src/corelib/plugin/qlibrary_win.cpp +++ b/src/corelib/plugin/qlibrary_win.cpp @@ -147,7 +147,6 @@ bool QLibraryPrivate::load_sys() qualifiedFileName = moduleFileName; else qualifiedFileName = dir.filePath(moduleFileName); -#endif // !Q_OS_WINRT if (loadHints() & QLibrary::PreventUnloadHint) { // prevent the unloading of this component @@ -157,7 +156,9 @@ bool QLibraryPrivate::load_sys() reinterpret_cast(pHnd), &hmod); Q_ASSERT(!ok || hmod == pHnd); + Q_UNUSED(ok); } +#endif // !Q_OS_WINRT } return (pHnd != 0); } -- cgit v1.2.3 From f5aa65349cf567dbbd512cbf8d08f5968e9c462a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 28 Apr 2016 09:51:24 +0200 Subject: QFactoryLoader: use new QJsonObject::value(QLatin1String) Allows to get rid of some QStringLiterals, reducing QtCore text size by ~800b. Change-Id: I8f7e57927163eaaf628e42020f83f053faea6bf8 Reviewed-by: Lars Knoll --- src/corelib/plugin/qfactoryloader.cpp | 38 ++++++++++------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'src/corelib/plugin') diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index dce750b5ad..6cd02e3a3f 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -56,18 +56,6 @@ QT_BEGIN_NAMESPACE -namespace { - -// avoid duplicate QStringLiteral data: -inline QString iidKeyLiteral() { return QStringLiteral("IID"); } -#ifdef QT_SHARED -inline QString versionKeyLiteral() { return QStringLiteral("version"); } -#endif -inline QString metaDataKeyLiteral() { return QStringLiteral("MetaData"); } -inline QString keysKeyLiteral() { return QStringLiteral("Keys"); } - -} - class QFactoryLoaderPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QFactoryLoader) @@ -163,12 +151,12 @@ void QFactoryLoader::update() QStringList keys; bool metaDataOk = false; - QString iid = library->metaData.value(iidKeyLiteral()).toString(); + QString iid = library->metaData.value(QLatin1String("IID")).toString(); if (iid == QLatin1String(d->iid.constData(), d->iid.size())) { - QJsonObject object = library->metaData.value(metaDataKeyLiteral()).toObject(); + QJsonObject object = library->metaData.value(QLatin1String("MetaData")).toObject(); metaDataOk = true; - QJsonArray k = object.value(keysKeyLiteral()).toArray(); + QJsonArray k = object.value(QLatin1String("Keys")).toArray(); for (int i = 0; i < k.size(); ++i) keys += d->cs ? k.at(i).toString() : k.at(i).toString().toLower(); } @@ -191,9 +179,9 @@ void QFactoryLoader::update() QLibraryPrivate *previous = d->keyMap.value(key); int prev_qt_version = 0; if (previous) { - prev_qt_version = (int)previous->metaData.value(versionKeyLiteral()).toDouble(); + prev_qt_version = (int)previous->metaData.value(QLatin1String("version")).toDouble(); } - int qt_version = (int)library->metaData.value(versionKeyLiteral()).toDouble(); + int qt_version = (int)library->metaData.value(QLatin1String("version")).toDouble(); if (!previous || (prev_qt_version > QT_VERSION && qt_version <= QT_VERSION)) { d->keyMap[key] = library; ++keyUsageCount; @@ -274,7 +262,7 @@ QList QFactoryLoader::metaData() const const auto staticPlugins = QPluginLoader::staticPlugins(); for (const QStaticPlugin &plugin : staticPlugins) { const QJsonObject object = plugin.metaData(); - if (object.value(iidKeyLiteral()) != QLatin1String(d->iid.constData(), d->iid.size())) + if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size())) continue; metaData.append(object); } @@ -308,7 +296,7 @@ QObject *QFactoryLoader::instance(int index) const QVector staticPlugins = QPluginLoader::staticPlugins(); for (int i = 0; i < staticPlugins.count(); ++i) { const QJsonObject object = staticPlugins.at(i).metaData(); - if (object.value(iidKeyLiteral()) != QLatin1String(d->iid.constData(), d->iid.size())) + if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size())) continue; if (index == 0) @@ -322,12 +310,10 @@ QObject *QFactoryLoader::instance(int index) const QMultiMap QFactoryLoader::keyMap() const { QMultiMap result; - const QString metaDataKey = metaDataKeyLiteral(); - const QString keysKey = keysKeyLiteral(); const QList metaDataList = metaData(); for (int i = 0; i < metaDataList.size(); ++i) { - const QJsonObject metaData = metaDataList.at(i).value(metaDataKey).toObject(); - const QJsonArray keys = metaData.value(keysKey).toArray(); + const QJsonObject metaData = metaDataList.at(i).value(QLatin1String("MetaData")).toObject(); + const QJsonArray keys = metaData.value(QLatin1String("Keys")).toArray(); const int keyCount = keys.size(); for (int k = 0; k < keyCount; ++k) result.insert(i, keys.at(k).toString()); @@ -337,12 +323,10 @@ QMultiMap QFactoryLoader::keyMap() const int QFactoryLoader::indexOf(const QString &needle) const { - const QString metaDataKey = metaDataKeyLiteral(); - const QString keysKey = keysKeyLiteral(); const QList metaDataList = metaData(); for (int i = 0; i < metaDataList.size(); ++i) { - const QJsonObject metaData = metaDataList.at(i).value(metaDataKey).toObject(); - const QJsonArray keys = metaData.value(keysKey).toArray(); + const QJsonObject metaData = metaDataList.at(i).value(QLatin1String("MetaData")).toObject(); + const QJsonArray keys = metaData.value(QLatin1String("Keys")).toArray(); const int keyCount = keys.size(); for (int k = 0; k < keyCount; ++k) { if (!keys.at(k).toString().compare(needle, Qt::CaseInsensitive)) -- cgit v1.2.3