Load Plugins from QStandardPaths::AppDataLocation

This commit is contained in:
Florian Märkl 2019-02-09 14:16:33 +01:00
parent 986041380c
commit ea6dea3cc1
2 changed files with 10 additions and 10 deletions

View File

@ -11,6 +11,7 @@
#include <QDir>
#include <QCoreApplication>
#include <QPluginLoader>
#include <QStandardPaths>
Q_GLOBAL_STATIC(PluginManager, uniqueInstance)
@ -31,27 +32,26 @@ void PluginManager::loadPlugins()
{
assert(plugins.isEmpty());
QDir pluginsDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (pluginsDir.dirName() == "MacOS") {
pluginsDir.cdUp();
pluginsDir.cdUp();
pluginsDir.cdUp();
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
if (locations.isEmpty()) {
qCritical() << "Failed to get a standard path to load plugins from.";
return;
}
#endif
QDir pluginsDir(locations.first());
pluginsDir.mkdir("plugins");
if (!pluginsDir.cd("plugins")) {
return;
}
QDir nativePluginsDir = pluginsDir;
nativePluginsDir.mkdir("native");
if (nativePluginsDir.cd("native")) {
loadNativePlugins(nativePluginsDir);
}
QDir pythonPluginsDir = pluginsDir;
pythonPluginsDir.mkdir("python");
if (pythonPluginsDir.cd("python")) {
loadPythonPlugins(pythonPluginsDir.absolutePath());
}