本文整理汇总了C++中QPluginLoader类的典型用法代码示例。如果您正苦于以下问题:C++ QPluginLoader类的具体用法?C++ QPluginLoader怎么用?C++ QPluginLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPluginLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qDebug
void suiPluginManager::loadPlugin(const QString &fileName)
{
qDebug() << "Load plugin: " << fileName;
if (mPluginLoaders.find(fileName) != mPluginLoaders.end())
SuiExcept(SuiExceptionDuplicateItem,
QString("Plugin '%1' already loaded").arg(fileName),
"void suiPluginManager::loadPlugin(const QString &fileName)");
QPluginLoader *loader = new QPluginLoader(fileName, this);
if (!loader->load())
{
qDebug() << loader->errorString();
SuiExcept(SuiExceptionInternalError,
QString("Can't load plugin '%1'").arg(fileName),
"void suiPluginManager::loadPlugin(const QString &fileName)");
}
// process instances
UiPluginInterface *plugInterface = qobject_cast<UiPluginInterface*>(loader->instance());
if (plugInterface != 0)
{
mPluginLoaders[fileName] = loader;
processLoadPlugin(plugInterface);
}else
{
delete loader;
SuiExcept(SuiExceptionInternalError,
QString("There are no plugin interface in '%1'").arg(fileName),
"void suiPluginManager::loadPlugin(const QString &fileName)");
}
}
示例2: mCustomizer
ToolPluginManager::ToolPluginManager()
: mCustomizer()
{
mPluginsDir = QDir(qApp->applicationDirPath());
while (!mPluginsDir.isRoot() && !mPluginsDir.entryList(QDir::Dirs).contains("plugins")) {
mPluginsDir.cdUp();
}
mPluginsDir.cd("plugins");
for (QString const &fileName : mPluginsDir.entryList(QDir::Files)) {
// TODO: Free memory
QPluginLoader *loader = new QPluginLoader(mPluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader->instance();
if (plugin) {
ToolPluginInterface *toolPlugin = qobject_cast<ToolPluginInterface *>(plugin);
if (toolPlugin) {
mPlugins << toolPlugin;
mLoaders << loader;
} else {
// TODO: Does not work on linux. See editorManager.cpp for more details.
// loader->unload();
delete loader;
}
} else {
loader->unload();
delete loader;
}
}
loadDefaultSettings();
setHotKeyActions();
}
示例3: loadMySqlDriver
void loadMySqlDriver()
{
QPluginLoader loader;
loader.setFileName("/opt/qtsdk-2010.04/qt/plugins/sqldrivers/libqsqlmysql.so");
qDebug()<<loader.load();
qDebug()<<loader.errorString();
}
示例4: documentType
int Global::documentType(const QUrl& document)
{
QMimeType mime = QMimeDatabase{}.mimeTypeForUrl(document);
QList<QPluginLoader*> plugins = KoJsonTrader::self()->query("Calligra/Part", mime.name());
for (int i = 0; i < plugins.count(); i++) {
QPluginLoader* loader = plugins.at(i);
if(loader->fileName().contains("words")) {
return DocumentType::TextDocument;
} else if(loader->fileName().contains("sheets")) {
return DocumentType::Spreadsheet;
} else if(loader->fileName().contains("stage")) {
return DocumentType::Presentation;
}
}
// Since we don't actually have a Calligra plugin that handles these...
if(staticTextTypes.contains(mime.name())) {
return DocumentType::StaticTextDocument;
}
return DocumentType::Unknown;
}
示例5: QObject
AExtensionFactoryPrivate::AExtensionFactoryPrivate()
: QObject( qApp )
{
QString extensionsDirName;
AExtensionInterface *iface = 0;
QObject *plugin = 0;
QPluginLoader pluginLoader;
#ifdef Q_OS_WIN32
extensionsDirName = qApp->applicationDirPath()+"/extensions";
#else
extensionsDirName = "/usr/lib/ananas4/extensions";
#endif
hash.clear();
extensionKeys.clear();
QDir extensionsDirectory( extensionsDirName );
QStringList extensionFiles = extensionsDirectory.entryList( QDir::Files );
QString fileName = extensionFiles.first();
for (int i=0; i<extensionFiles.count(); i++){
fileName = extensionFiles[i];
pluginLoader.setFileName( extensionsDirectory.absoluteFilePath( fileName ) );
plugin = pluginLoader.instance();
if (plugin) {
iface = qobject_cast<AExtensionInterface *>(plugin);
if( iface ) {
extensionKeys.append( iface->key());
hash[ iface->key()] = iface;
}
}
}
}
示例6: Q_D
void AbstractPluginLoader::loadPlugins(const QRegExp& fileRx, QVector<QString>* errors)
{
Q_D(AbstractPluginLoader);
const QDir pluginsFolder(this->loadingFolder());
QStringList entries(pluginsFolder.entryList(QDir::Files));
foreach (const QString& entry, entries) {
if (fileRx.indexIn(entry) != -1 && ::isLibrary(entry)) {
// Try to load the plugin
#ifdef DEBUG_ABSTRACT_PLUGIN_LOADER
qDebug() << "try to load" << entry;
#endif // DEBUG_ABSTRACT_PLUGIN_LOADER
QPluginLoader* pluginLoader = new QPluginLoader(pluginsFolder.absoluteFilePath(entry));
QObject* plugin = pluginLoader->instance();
// Is the plugin compatible ?
if (this->isPluginCompatible(plugin)) {
d->m_plugins.append(plugin);
d->m_pluginLoaders.append(pluginLoader);
d->m_pluginFilenames.insert(plugin, entry);
}
else {
#ifdef DEBUG_ABSTRACT_PLUGIN_LOADER
qDebug() << " not added";
#endif // DEBUG_ABSTRACT_PLUGIN_LOADER
if (errors != NULL)
//: %1 holds the path to a plugin (DLL)
//: %2 holds an error description
errors->append(QObject::tr("Failed to load plugin (maybe wrong interface) %1 : %2")
.arg(pluginLoader->fileName())
.arg(pluginLoader->errorString()));
pluginLoader->unload();
delete pluginLoader;
} // end if (this->isPluginCompatible(plugin))
} // end if (fileRx.indexIn(entry) != -1)
} // end foreach ()
}
示例7: QWidget
PluginConfigWidget::PluginConfigWidget(QHash<QString, QPluginLoader*> plugins,
QWidget* parent) : QWidget(parent) {
_plugins = plugins;
//qDebug() << "* plugins for PluginConfigWidget:" << _plugins;
QWidget* window = new QWidget();
QStandardItemModel* model = new QStandardItemModel(window);
QStandardItem* parentItem = model->invisibleRootItem();
QStringList labels;
labels << "Plugin" << "Description";
model->setHorizontalHeaderLabels(labels);
QPluginLoader* pl;
foreach(pl, _plugins) {
MClientPluginInterface* ip =
qobject_cast<MClientPluginInterface*>(pl->instance());
if(!ip) continue;
QList<QStandardItem*> itemList;
QStandardItem* first = new QStandardItem(ip->longName());
first->setData(ip->shortName(), Qt::UserRole);
itemList.append(first);
itemList.append(new QStandardItem(ip->description()));
QStandardItem* item;
foreach(item, itemList) {
item->setEditable(false);
}
示例8: getVKBFactories
static QList<VirtualKeyboardFactory *> getVKBFactories()
{
QList<VirtualKeyboardFactory *> list;
QString path("/usr/lib/luna");
qDebug() << "\033[1;33;45m" << Q_FUNC_INFO << "Searching for VKB plugins in" << path << "\033[0m";
QDir plugindir = QDir(path);
QStringList files = plugindir.entryList(QDir::Files);
qDebug() << "\033[1;33;45m" << Q_FUNC_INFO << "Found" << files.count() << "files" << "\033[0m";
QPluginLoader loader;
QStringList::const_iterator it = files.constBegin();
while (it != files.constEnd()) {
qDebug() << "\033[1;33;40m" << Q_FUNC_INFO << "Checking" << (*it) << "\033[0m";
loader.setFileName(plugindir.absoluteFilePath(*it));
VirtualKeyboardFactory *factory =
qobject_cast<VirtualKeyboardFactory *>(loader.instance());
if (factory) {
qDebug() << "\033[1;32;40m" << Q_FUNC_INFO << "Loaded plugin"
<< (*it) << "successfully" << "\033[0m";
list.append(factory);
} else {
qWarning() << "\033[1;31;40m" << Q_FUNC_INFO << "Failed to load"
<< (*it) << "\n" << loader.errorString() << "\033[0m";
}
++it;
}
return list;
}
示例9: QPluginLoader
void PluginManager::scanPlugins(bool initialScan) {
if (initialScan) {
QFileInfoList list = _pluginPath.entryInfoList();
for (QFileInfo info : list) {
QPluginLoader* loader = new QPluginLoader(info.absoluteFilePath(), this);
QJsonObject metaData = loader->metaData().value("MetaData").toObject();
const QString name = metaData.value("name").toString("Unknown");
const QString role = metaData.value("role").toString("Unknown");
// Ensure IID is inserted.
metaData.insert("IID", loader->metaData().value("IID"));
AdamantPluginInfo* data = new AdamantPluginInfo;
data->state = PluginState::Unknown;
data->name = name;
data->role = role;
data->metaData = metaData;
data->instance = nullptr;
data->script = nullptr;
data->loader = nullptr;
data->file = info;
data->lastModified = info.lastModified();
_pluginsByRole.insertMulti(role, data);
emit pluginDiscovered(name);
loader->deleteLater();
}
}
}
示例10: QPluginLoader
HsWidget* HsWidgetFactoryPrivate::createWidget(const HsWidgetToken &token)
{
QPluginLoader* loader = new QPluginLoader(token.mLibrary);
QObject* plugin = loader->instance();
IHsWidgetProvider* provider = qobject_cast<IHsWidgetProvider*>(plugin);
HsWidget* widget(0);
if (provider) {
widget = provider->createWidget(token);
if (!widget) {
HSDEBUG("Widget creation failed.")
loader->unload();
delete loader;
}
else {
HsPluginUnloader* p = new HsPluginUnloader(loader);
p->connect(widget,SIGNAL(destroyed()),SLOT(deleteLater()));
}
}
else {
HSDEBUG("Widget creation failed - No provider.")
loader->unload();
delete loader;
}
return widget;
}
示例11: unloadModelComponentInfoById
bool ComponentManager::unloadModelComponentInfoById(const QString& id)
{
if(m_modelComponentInfoById.contains(id))
{
IModelComponentInfo* componentInfo = m_modelComponentInfoById[id];
if (m_modelComponentInfoHash.contains(componentInfo))
{
QPluginLoader* plugin = m_modelComponentInfoHash[componentInfo];
m_modelComponentInfoHash.remove(componentInfo);
m_modelComponentInfoById.remove(id);
emit modelComponentInfoUnloaded(componentInfo->id());
emit postMessage("Model component library " + componentInfo->id() + " unloaded");
plugin->unload();
return true;
}
else
{
emit postMessage("Unable to unload model component library " + componentInfo->id());
return false;
}
}
else
{
return false;
}
}
示例12: qDebug
void PluginManager::loadPlugin(QString const & path)
{
qDebug() << "Load plugin: " << path;
Q_ASSERT(mPluginLoaders.find(path) == mPluginLoaders.end());
QPluginLoader * loader = new QPluginLoader(path, this);
if (!loader->load())
{
qDebug() << loader->errorString();
qDebug() << QString("Can't load plugin '%1'").arg(path);
}
// process instances
PluginInterface *plugInterface = qobject_cast<PluginInterface*>(loader->instance());
if (plugInterface != 0)
{
mPluginLoaders[path] = loader;
processLoadPlugin(plugInterface);
}else
{
delete loader;
qDebug() << QString("There are no plugin interface in '%1'").arg(path);
}
}
示例13: QPluginLoader
/*!
Creates and returns a screensaver on the given token.
\param token Identifies the screensaver to be created.
\return The created state.
*/
Screensaver* ScreensaverFactoryPrivate::createScreensaver(const ScreensaverToken &token)
{
QStringList pluginPaths;
// check plugin dirs from root of different drives
QFileInfoList drives = QDir::drives();
for(int i=0; i < drives.count(); i++) {
QFileInfo drive = drives.at(i);
QString driveLetter = drive.absolutePath();
QString path = driveLetter + mPluginDirectory;
if (QDir(path).exists()) {
pluginPaths << path;
}
}
// check plugin dir relative to current dir
if (QDir(mPluginDirectory).exists() &&
!pluginPaths.contains(QDir(mPluginDirectory).absolutePath())) {
pluginPaths << mPluginDirectory;
}
IScreensaverProvider *provider(0);
QPluginLoader *loader = new QPluginLoader();
QObject *plugin(0);
for(int i=0; i < pluginPaths.count(); i++) {
QString path = pluginPaths.at(i);
QString fileName = QDir(path).absoluteFilePath(token.mLibrary);
loader->setFileName(fileName);
plugin = loader->instance();
provider = qobject_cast<IScreensaverProvider*>(plugin);
if (provider) {
break;
}
}
Screensaver *screensaver(0);
if (provider) {
screensaver = provider->createScreensaver(token);
if (!screensaver) {
qWarning() << "Screensaver creation failed.";
qWarning() << token.mLibrary << "cannot provide" << token.mUri;
loader->unload();
delete loader;
} else {
// unload plugin once screensaver gets deleted
ScreensaverPluginUnloader *unloader = new ScreensaverPluginUnloader(loader);
unloader->connect(screensaver, SIGNAL(destroyed()), SLOT(deleteLater()));
}
} else {
qDebug() << "Screensaver creation failed.";
qWarning() << token.mLibrary << "- provider not found";
loader->unload();
delete loader;
}
return screensaver;
}
示例14: loadHints
void tst_QPluginLoader::loadHints()
{
QPluginLoader loader;
QCOMPARE(loader.loadHints(), (QLibrary::LoadHints)0); //Do not crash
loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
loader.setFileName( sys_qualifiedLibraryName("theplugin")); //a plugin
QCOMPARE(loader.loadHints(), QLibrary::ResolveAllSymbolsHint);
}
示例15: pluginsBlacklist
ISCORE_LIB_BASE_EXPORT
std::pair<QString, iscore::Plugin_QtInterface*> PluginLoader::loadPlugin(
const QString &fileName,
const std::vector<iscore::Plugin_QtInterface*>& availablePlugins)
{
#if !defined(ISCORE_STATIC_QT)
auto blacklist = pluginsBlacklist();
QPluginLoader loader {fileName};
if(QObject* plugin = loader.instance())
{
auto iscore_plugin = dynamic_cast<iscore::Plugin_QtInterface*>(plugin);
if(!iscore_plugin)
{
qDebug() << "Warning: plugin"
<< plugin->metaObject()->className()
<< "is not an i-score plug-in.";
return {};
}
// Check if the plugin is not already loaded
auto plug_it =
find_if(availablePlugins,
[&] (iscore::Plugin_QtInterface* obj)
{ return obj->key() == iscore_plugin->key(); });
if(plug_it != availablePlugins.end())
{
qDebug() << "Warning: plugin"
<< plugin->metaObject()->className()
<< "was already loaded. Not reloading.";
return std::make_pair(fileName, nullptr);
}
// Check if it is blacklisted
if(blacklist.contains(fileName))
{
plugin->deleteLater();
return std::make_pair(fileName, nullptr);
}
// We can load the plug-in
return std::make_pair(fileName, iscore_plugin);
}
else
{
QString s = loader.errorString();
if(!s.contains("Plugin verification data mismatch") && !s.contains("is not a Qt plugin"))
qDebug() << "Error while loading" << fileName << ": " << loader.errorString();
return {};
}
#endif
return {};
}