From 247dc18789c64ee6b7d5ec0e05e52522d1db46a1 2017-12-11 21:41:33 From: Alexis Jeandet Date: 2017-12-11 21:41:33 Subject: [PATCH] Added static plugin support In case of fully static exe even plugins must be static to allow single file executable. Small fix, when using resources in app from library they must be initialized with Q_INIT_RESOURCE. Signed-off-by: Alexis Jeandet --- diff --git a/app/src/Main.cpp b/app/src/Main.cpp index 30db0fe..9246498 100644 --- a/app/src/Main.cpp +++ b/app/src/Main.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -41,6 +42,13 @@ const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); int main(int argc, char *argv[]) { +#ifdef QT_STATICPLUGIN + Q_IMPORT_PLUGIN(MockPlugin) + Q_IMPORT_PLUGIN(AmdaPlugin) + Q_INIT_RESOURCE(amdaresources); +#endif + Q_INIT_RESOURCE(sqpguiresources); + SqpApplication a{argc, argv}; SqpApplication::setOrganizationName("LPP"); SqpApplication::setOrganizationDomain("lpp.fr"); @@ -75,6 +83,7 @@ int main(int argc, char *argv[]) pluginManager.loadPlugins(directory); } } + pluginManager.loadStaticPlugins(); return a.exec(); } diff --git a/core/include/Plugin/PluginManager.h b/core/include/Plugin/PluginManager.h index dd76163..025e42b 100644 --- a/core/include/Plugin/PluginManager.h +++ b/core/include/Plugin/PluginManager.h @@ -25,11 +25,16 @@ public: */ void loadPlugins(const QDir &pluginDir); + /** + * Loads static plugins into SciQlop. SciQLOP supports statically linked plugins. + */ + void loadStaticPlugins(); + /// @returns the number of plugins loaded int nbPluginsLoaded() const noexcept; private: - class PluginManagerPrivate; + struct PluginManagerPrivate; spimpl::unique_impl_ptr impl; }; diff --git a/core/src/Plugin/PluginManager.cpp b/core/src/Plugin/PluginManager.cpp index c1fa918..2f07645 100644 --- a/core/src/Plugin/PluginManager.cpp +++ b/core/src/Plugin/PluginManager.cpp @@ -95,6 +95,15 @@ struct PluginManager::PluginManagerPrivate { loadState.log(); } + void loadStaticPlugins() + { + for (QObject *plugin : QPluginLoader::staticInstances()) + { + qobject_cast(plugin)->initialize(); + m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin"); + } + } + /// Registered plugins (key: plugin name, value: plugin path) QHash m_RegisteredPlugins; }; @@ -118,6 +127,11 @@ void PluginManager::loadPlugins(const QDir &pluginDir) } } +void PluginManager::loadStaticPlugins() +{ + impl->loadStaticPlugins(); +} + int PluginManager::nbPluginsLoaded() const noexcept { return impl->m_RegisteredPlugins.size();