本文整理汇总了C++中QPluginLoader::instance方法的典型用法代码示例。如果您正苦于以下问题:C++ QPluginLoader::instance方法的具体用法?C++ QPluginLoader::instance怎么用?C++ QPluginLoader::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPluginLoader
的用法示例。
在下文中一共展示了QPluginLoader::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadPlugins
void GLWidget::loadPlugins(const QStringList& list) {
QStringList::ConstIterator it = list.constBegin();
while(it != list.constEnd())
{
QString name = *it;
QPluginLoader *loader = new QPluginLoader(name);
if (! loader->load()) {
qDebug() << "Could not load plugin " << name << "\n";
qDebug() << loader->errorString() << "\n";
}
if (loader->isLoaded())
{
qDebug() << "Loaded plugin: " << loader->fileName(); // << endl;
QObject *plugin = loader->instance();
if (plugin)
{
plugins.push_back(loader);
BasicPlugin *plugin = qobject_cast<BasicPlugin *>(loader->instance());
// initialize plugin
if (plugin)
{
plugin->setWidget(this);
plugin->setArgs(mainArgs);
plugin->onPluginLoad();
if (plugin->drawScene()) // overrides drawScene?
drawPlugin = plugin;
}
}
}
else
{
qDebug() << "Load error: " << name << endl;
delete loader;
}
++it;
}
// make sure all plugins know about the latest plugin that overrides drawScene
for (unsigned int i=0; i<plugins.size(); ++i)
{
BasicPlugin *plugin = qobject_cast<BasicPlugin *>(plugins[i]->instance());
if (plugin)
plugin->setDrawPlugin(drawPlugin);
else
{
qDebug() << "Error: the plugin must implement the BasicPlugin interface" << endl <<
" Example: " << endl <<
" Q_INTERFACES(BasicPlugin)" << endl;
}
}
resetCamera();
}
示例2: path
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;
}
示例3: createScreensaver
/*!
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;
}
示例4: loadPlugin
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);
}
}
示例5: createWidget
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;
}
示例6: 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();
}
示例7: loadPlugins
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 ()
}
示例8: extensionsDirectory
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;
}
}
}
}
示例9: 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);
}
示例10: loadPlugin
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)");
}
}
示例11: make_pair
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 {};
}
示例12: QDialog
SelectPluginDlg::SelectPluginDlg(QWidget * parent, const V3DPluginCallback2 & _callback)
: QDialog(parent)
{
setMinimumWidth(500);
parent = parent;
callback = (V3DPluginCallback2 *) (&(_callback));
QVBoxLayout * layout = new QVBoxLayout;
//tree widget GUI
pluginTreeWidget = new QTreeWidget();
pluginTreeWidget->setColumnCount(1);
pluginTreeWidget->header()->hide();
pluginTreeWidget->setSortingEnabled(false);
if (!setPluginRootPathAutomaticly())
v3d_msg("You don't have any plugins on neuron utilities");
QStringList fileList;
getAllFiles(toolboxRootPath, fileList);
root_path = toolboxRootPath;
for (int i=0;i<fileList.size();i++)
{
QString file = fileList[i];
QPluginLoader* loader = new QPluginLoader(file);
if(!loader)
{
cerr<<"unable to load plugin: "<<qPrintable(file)<<endl;
continue;
}
QObject * plugin = loader->instance();
if (plugin)
{
//lib - top level item
QTreeWidgetItem *pluginItem = new QTreeWidgetItem(pluginTreeWidget);
QString tmp = file.remove(0, root_path.size()+1);
tmp.chop(file.section("/", -1).size()+1);
pluginItem->setText(0, tmp);
pluginTreeWidget->addTopLevelItem(pluginItem);
name_table.insert(pluginItem,fileList[i]);
QStringList menulist = v3d_getInterfaceMenuList(plugin);
foreach(QString menu_name, menulist)
{
//menu - second level item
QTreeWidgetItem * menuItem = new QTreeWidgetItem(pluginItem);
menuItem->setText(0, menu_name);
}
}
loader->unload();
delete loader;
}
示例13: if
PluginInterface *Agros2D::loadPlugin(const QString &pluginName)
{
QPluginLoader *loader = NULL;
#ifdef Q_WS_X11
if (QFile::exists(QString("%1/libs/libagros2d_plugin_%2.so").arg(datadir()).arg(pluginName)))
loader = new QPluginLoader(QString("%1/libs/libagros2d_plugin_%2.so").arg(datadir()).arg(pluginName));
if (!loader)
{
if (QFile::exists(QString("/usr/local/lib/libagros2d_plugin_%1.so").arg(pluginName)))
loader = new QPluginLoader(QString("/usr/local/lib/libagros2d_plugin_%1.so").arg(pluginName));
else if (QFile::exists(QString("/usr/lib/libagros2d_plugin_%1.so").arg(pluginName)))
loader = new QPluginLoader(QString("/usr/lib/libagros2d_plugin_%1.so").arg(pluginName));
}
#endif
#ifdef Q_WS_WIN
if (QFile::exists(QString("%1/libs/agros2d_plugin_%2.dll").arg(datadir()).arg(pluginName)))
loader = new QPluginLoader(QString("%1/libs/agros2d_plugin_%2.dll").arg(datadir()).arg(pluginName));
#endif
if (!loader)
{
throw AgrosPluginException(QObject::tr("Could not find 'agros2d_plugin_%1'").arg(pluginName));
}
if (!loader->load())
{
QString error = loader->errorString();
delete loader;
throw AgrosPluginException(QObject::tr("Could not load 'agros2d_plugin_%1' (%2)").arg(pluginName).arg(error));
}
assert(loader->instance());
PluginInterface *plugin = qobject_cast<PluginInterface *>(loader->instance());
// loader->unload();
delete loader;
return plugin;
}
示例14: loadPlugins
void PluginManagerPrivate::loadPlugins()
{
if (m_pluginsLoaded)
{
return;
}
QTime t;
t.start();
mDebug() << "Starting to load Plugins.";
QStringList pluginFileNameList = MarbleDirs::pluginEntryList( "", QDir::Files );
MarbleDirs::debug();
Q_ASSERT( m_renderPluginTemplates.isEmpty() );
Q_ASSERT( m_positionProviderPluginTemplates.isEmpty() );
Q_ASSERT( m_searchRunnerPlugins.isEmpty() );
Q_ASSERT( m_reverseGeocodingRunnerPlugins.isEmpty() );
Q_ASSERT( m_routingRunnerPlugins.isEmpty() );
Q_ASSERT( m_parsingRunnerPlugins.isEmpty() );
foreach( const QString &fileName, pluginFileNameList ) {
// mDebug() << fileName << " - " << MarbleDirs::pluginPath( fileName );
QString const path = MarbleDirs::pluginPath( fileName );
QPluginLoader* loader = new QPluginLoader( path );
QObject * obj = loader->instance();
if ( obj ) {
bool isPlugin = appendPlugin<RenderPlugin, RenderPluginInterface>
( obj, loader, m_renderPluginTemplates );
isPlugin = isPlugin || appendPlugin<PositionProviderPlugin, PositionProviderPluginInterface>
( obj, loader, m_positionProviderPluginTemplates );
isPlugin = isPlugin || appendPlugin<SearchRunnerPlugin, SearchRunnerPlugin>
( obj, loader, m_searchRunnerPlugins ); // intentionally T==U
isPlugin = isPlugin || appendPlugin<ReverseGeocodingRunnerPlugin, ReverseGeocodingRunnerPlugin>
( obj, loader, m_reverseGeocodingRunnerPlugins ); // intentionally T==U
isPlugin = isPlugin || appendPlugin<RoutingRunnerPlugin, RoutingRunnerPlugin>
( obj, loader, m_routingRunnerPlugins ); // intentionally T==U
isPlugin = isPlugin || appendPlugin<ParseRunnerPlugin, ParseRunnerPlugin>
( obj, loader, m_parsingRunnerPlugins ); // intentionally T==U
if ( !isPlugin ) {
qWarning() << "Ignoring the following plugin since it couldn't be loaded:" << path;
mDebug() << "Plugin failure:" << path << "is a plugin, but it does not implement the "
<< "right interfaces or it was compiled against an old version of Marble. Ignoring it.";
delete loader;
}
} else {
qWarning() << "Ignoring to load the following file since it doesn't look like a valid Marble plugin:" << path << endl
<< "Reason:" << loader->errorString();
delete loader;
}
}
示例15: pluginAt
CntUiExtensionFactory* CntExtensionManager::pluginAt( int index)
{
loadExtensionPlugins();
QPluginLoader* pluginLoader = mPlugins[index];
QObject *plugin = pluginLoader->instance();
if (plugin)
{
return qobject_cast<CntUiExtensionFactory*>(plugin);
}
return NULL;
}