5 #include <QCoreApplication>
6 #include <QPluginLoader>
11 template <
typename ImplType,
typename Interface> std::shared_ptr<ImplType>
loadPlugin(std::string name)
13 std::shared_ptr<ImplType> ret;
20 QString path = QString::fromStdString(name);
22 QString path = QCoreApplication::applicationDirPath() / QString::fromStdString(
"../lib/lib" + name +
".so");
25 char const *
const c_name = name.c_str();
28 QPluginLoader loader(path);
29 Interface *plugin =
dynamic_cast<Interface *
>(loader.instance());
31 ret = std::shared_ptr<ImplType>(plugin->create());
33 qDebug() << QString::asprintf(
"%s is loaded successfully.", c_name);
35 qDebug() << QString::asprintf(
"Failed to load the plugin %s", c_name);
39 qDebug() << loader.errorString();
std::shared_ptr< ImplType > loadPlugin(std::string name)
Definition: LoadPlugin.h:11
#define logprintf(LEVEL, FMT,...)
Definition: Logger.h:61
#define LOG_DEFAULT
Definition: Logger.h:5