コード例 #1
0
ファイル: main.cpp プロジェクト: xian0gang/test
void loadMySqlDriver()
{
    QPluginLoader loader;
    loader.setFileName("/opt/qtsdk-2010.04/qt/plugins/sqldrivers/libqsqlmysql.so");
    qDebug()<<loader.load();
    qDebug()<<loader.errorString();
}
コード例 #2
0
ファイル: suipluginmanager.cpp プロジェクト: asvitenkov/sui
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)");
    }
}
コード例 #3
0
ファイル: pluginmanager.cpp プロジェクト: AlexKlybik/kbe
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);
    }

}
コード例 #4
0
void PluginLoaderThread::run()
{
    if (m_queue.empty() || m_targetThread == 0) {
        qCritical() << "Invalid plugin loading parameters";
        return;
    }

    while (!m_queue.isEmpty()) {
        QPluginLoader * loader = new QPluginLoader ();
        loader->setFileName (m_queue.takeFirst());
        loader->setLoadHints (QLibrary::ExportExternalSymbolsHint);

        if (loader->load()) {
            QMutexLocker locker(&m_mutex);
            if (!m_abort) {
                loader->moveToThread(m_targetThread);
                //loader->setParent(parent());
            }
            else {
                qDebug() << "Plugin loading aborted, exiting loader thread";
                delete loader;
                loader = 0;
                break;
            }
        }
        else {
            qCritical() << "Failed to load plugin:" << loader->errorString();
            delete loader;
            loader = 0;
        }

        Q_EMIT(pluginLoaded(loader, m_queue.isEmpty()));
    }
}
コード例 #5
0
ファイル: glwidget.cpp プロジェクト: EikaNN/FIB-G
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();
}
コード例 #6
0
void tst_QPluginLoader::reloadPlugin()
{
    QPluginLoader loader;
    loader.setFileName( sys_qualifiedLibraryName("theplugin"));     //a plugin
    loader.load(); // not recommended, instance() should do the job.
    PluginInterface *instance = qobject_cast<PluginInterface*>(loader.instance());
    QVERIFY(instance);
    QCOMPARE(instance->pluginName(), QLatin1String("Plugin ok"));

    QSignalSpy spy(loader.instance(), SIGNAL(destroyed()));
    QVERIFY(spy.isValid());
    QVERIFY(loader.unload());   // refcount reached 0, did really unload
    QCOMPARE(spy.count(), 1);

    // reload plugin
    QVERIFY(loader.load());
    QVERIFY(loader.isLoaded());

    PluginInterface *instance2 = qobject_cast<PluginInterface*>(loader.instance());
    QVERIFY(instance2);
    QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));

    QVERIFY(loader.unload());
}
コード例 #7
0
 // looking for dynamic plugins
 foreach(const QFileInfo & fileName, files)
 {
     emit log((int)LogDebug, MODULENAME, QString("Loading plugin: %1").arg(fileName.fileName()), "");
     QPluginLoader loader;
     loader.setLoadHints(QLibrary::ResolveAllSymbolsHint|QLibrary::ExportExternalSymbolsHint);
     loader.setFileName( fileName.absoluteFilePath());
     if (!loader.load())
     {
         qCritical() << loader.errorString();
         continue;
     }
     QObject *plugin = loader.instance();
     if (plugin && qobject_cast<PropertyInterface*>(plugin))
         m_plugins.push_back(qobject_cast<PropertyInterface*>(plugin));
     else
         emit log((int)LogWarning, MODULENAME, QString("It\'s not a PropertyEditor plugin: %1").arg(fileName.fileName()), "");
 }
コード例 #8
0
ファイル: main.cpp プロジェクト: ahyangyi/fqterm
 void loadNecessaryQtPlugins() {
   static QPluginLoader qkrcodecsLoader( "qkrcodecs" );
   static QPluginLoader qcncodecsLoader( "qcncodecs" );
   static QPluginLoader qjpcodecsLoader( "qjpcodecs" );
   static QPluginLoader qtwcodecsLoader( "qtwcodecs" );
   static QPluginLoader qjpegLoader("qjpeg");
   static QPluginLoader qgifLoader("qgif");
   static QPluginLoader qmngLoader("qmng");
  
   qkrcodecsLoader.load();
   qcncodecsLoader.load();
   qjpcodecsLoader.load();
   qtwcodecsLoader.load();
   qjpegLoader.load();
   qgifLoader.load();
   qmngLoader.load();
 }
コード例 #9
0
ファイル: global.cpp プロジェクト: LukasKoudela/agros2d
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;
}
コード例 #10
0
ファイル: form_interface.cpp プロジェクト: LeiDai/agros2d
// read forms
void readCustomForms(QMenu *menu)
{
    QDir dir(datadir() + "/libs/");

    QStringList filter;
    filter << "*agros2d_forms_*";
    QStringList list = dir.entryList(filter);

    foreach (QString filename, list)
    {
        QString fn = QString("%1/%2").arg(dir.absolutePath()).arg(filename);
        if (QFile::exists(fn))
        {
            QPluginLoader *loader = new QPluginLoader(fn);

            if (!loader)
            {
                throw AgrosException(QObject::tr("Could not find '%1'").arg(fn));
            }


            if (!loader->load())
            {
                qDebug() << loader->errorString();
                delete loader;
                throw AgrosException(QObject::tr("Could not load '%1'. %2").arg(fn).arg(loader->errorString()));
            }

            assert(loader->instance());
            FormInterface *form = qobject_cast<FormInterface *>(loader->instance());
            delete loader;

            if (form)
            {
                qDebug() << QString("Form '%1' loaded.").arg(form->formId());
                menu->addAction(form->action());
            }
        }
    }
コード例 #11
0
ファイル: editorManager.cpp プロジェクト: Esenin/qreal
bool EditorManager::loadPlugin(QString const &pluginName)
{
	QPluginLoader *loader = new QPluginLoader(mPluginsDir.absoluteFilePath(pluginName));
	loader->load();
	QObject *plugin = loader->instance();

	if (plugin) {
		EditorInterface *iEditor = qobject_cast<EditorInterface *>(plugin);
		if (iEditor) {
			mPluginsLoaded += iEditor->id();
			mPluginFileName.insert(iEditor->id(), pluginName);
			mPluginIface[iEditor->id()] = iEditor;
			mLoaders.insert(pluginName, loader);
			return true;
		}
	}

	QMessageBox::warning(NULL, tr("error"), tr("Plugin loading failed: ") + loader->errorString());
	loader->unload();
	delete loader;
	return false;
}
コード例 #12
0
        foreach (const QString &dir, dirsToCheck) {
            QVector<KPluginMetaData> metadataList = KPluginLoader::findPlugins(dir,
                [=](const KPluginMetaData &data)
            {
                return data.serviceTypes().contains("artikulate/libsound/backend");
            });

            foreach (const auto &metadata, metadataList) {
                loader.setFileName(metadata.fileName());
                qCDebug(LIBSOUND_LOG) << "Load Plugin: " << metadata.name();
                if (!loader.load()) {
                    qCCritical(LIBSOUND_LOG) << "Error while loading plugin: " << metadata.name();
                }
                KPluginFactory *factory = KPluginLoader(loader.fileName()).factory();
                if (!factory) {
                    qCCritical(LIBSOUND_LOG) << "Could not load plugin:" << metadata.name();
                    continue;
                }
                BackendInterface *plugin = factory->create<BackendInterface>(parent, QList< QVariant >());
                if (plugin->outputBackend()) {
                    m_backendList.append(plugin->outputBackend());
                }
            }
コード例 #13
0
QPair<QObject *, QString> PluginManagerImplementation::pluginLoadedByName(QString const &pluginName)
{
	QPluginLoader *loader = new QPluginLoader(mPluginsDir.absoluteFilePath(pluginName));
	loader->load();
	QObject *plugin = loader->instance();

	if (plugin) {
		mFileNameAndPlugin.insert(pluginName, plugin);
		return qMakePair(plugin, QString());
	}

	QString const loaderError = loader->errorString();

	// Unloading of plugins is currently (Qt 5.3) broken due to a bug in metatype system: calling Q_DECLARE_METATYPE
	// from plugin registers some data from plugin address space in Qt metatype system, which is not being updated
	// when plugin is unloaded and loaded again. Any subsequent calls to QVariant or other template classes/methods
	// which use metainformation will result in a crash. It is likely (but not verified) that qRegisterMetaType leads
	// to the same issue. Since we can not guarantee that plugin does not use Q_DECLARE_METATYPE or qRegisterMetaType
	// we shall not unload plugin at all, to be safe rather than sorry.
	//
	// But it seems also that metainformation gets deleted BEFORE plugins are unloaded on application exit, so we can
	// not call any metainformation-using code in destructors that get called on unloading. Since Qt classes themselves
	// are using such calls (QGraphicsViewScene, for example), random crashes on exit may be a symptom of this problem.
	//
	// EditorManager is an exception, because it really needs to unload editor plugins, to be able to load new versions
	// compiled by metaeditor. Editor plugins are generated, so we can guarantee to some extent that there will be no
	// metatype registrations.
	//
	// See:
	// http://stackoverflow.com/questions/19234703/using-q-declare-metatype-with-a-dll-that-may-be-loaded-multiple-times
	// (and http://qt-project.org/forums/viewthread/35587)
	// https://bugreports.qt-project.org/browse/QTBUG-32442

	delete loader;
	return qMakePair(nullptr, loaderError);
}
コード例 #14
0
ファイル: plugin.hpp プロジェクト: boradin/wintermute
 bool loadBinary() {
   loader->setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);
   return loader->load();
 }
コード例 #15
0
ファイル: core.cpp プロジェクト: addshore/huggle3-qt-lx
void Core::ExtensionLoad()
{
    QString path_ = Configuration::GetExtensionsRootPath();
    if (QDir().exists(path_))
    {
        QDir d(path_);
        QStringList extensions = d.entryList();
        int xx = 0;
        while (xx < extensions.count())
        {
            QString name = extensions.at(xx).toLower();
            if (name.endsWith(".so") || name.endsWith(".dll"))
            {
                name = QString(path_) + extensions.at(xx);
                QPluginLoader *extension = new QPluginLoader(name);
                if (extension->load())
                {
                    QObject* root = extension->instance();
                    if (root)
                    {
                        iExtension *interface = qobject_cast<iExtension*>(root);
                        if (!interface)
                        {
                            Huggle::Syslog::HuggleLogs->Log("Unable to cast the library to extension");
                        }else
                        {
                            if (interface->RequestNetwork())
                            {
                                interface->Networking = Query::NetworkManager;
                            }
                            if (interface->RequestConfiguration())
                            {
                                interface->Configuration = Configuration::HuggleConfiguration;
                            }
                            if (interface->RequestCore())
                            {
                                interface->HuggleCore = Core::HuggleCore;
                            }
                            if (interface->Register())
                            {
                                Core::Extensions.append(interface);
                                Huggle::Syslog::HuggleLogs->Log("Successfully loaded: " + extensions.at(xx));
                            }
                            else
                            {
                                Huggle::Syslog::HuggleLogs->Log("Unable to register: " + extensions.at(xx));
                            }
                        }
                    }
                } else
                {
                    Huggle::Syslog::HuggleLogs->Log("Failed to load (reason: " + extension->errorString() + "): " + extensions.at(xx));
                    delete extension;
                }
            } else if (name.endsWith(".py"))
            {
#ifdef PYTHONENGINE
                name = QString(path_) + extensions.at(xx);
                if (Core::Python->LoadScript(name))
                {
                    Huggle::Syslog::HuggleLogs->Log("Loaded python script: " + name);
                } else
                {
                    Huggle::Syslog::HuggleLogs->Log("Failed to load a python script: " + name);
                }
#endif
            }
            xx++;
        }
    } else
    {
        Huggle::Syslog::HuggleLogs->Log("There is no extensions folder, skipping load");
    }
    Huggle::Syslog::HuggleLogs->Log("Extensions: " + QString::number(Core::Extensions.count()));
}
コード例 #16
0
ファイル: main.cpp プロジェクト: SfietKonstantin/friends-qml
hosted_button_id=RZ2A2ZB93827Y";

int main(int argc, char **argv)
{
    QApplication app (argc, argv);
    app.setOrganizationName("SfietKonstantin");
    app.setApplicationName("qfb-mobile");

//    QFB::QueryManager queryManager;
    QFB::LoginManager loginManager;
    TokenManager tokenManager;
    Me me;
//    PostUpdateRelay postUpdateRelay;

    qmlRegisterType<UserInfoHelper>("org.SfietKonstantin.qfb.mobile", 4, 0, "QFBUserInfoHelper");
//    qmlRegisterType<BackPixmapItem>("org.SfietKonstantin.qfb.mobile", 4, 0,
//                                    "QFBBackPixmapItem");
    qmlRegisterType<PostHelper>("org.SfietKonstantin.qfb.mobile", 4, 0, "QFBPostHelper");
//    qmlRegisterType<MobilePostValidator>("org.SfietKonstantin.qfb.mobile", 4, 0,
//                                         "QFBMobilePostValidator");

    QDeclarativeView view;
#ifdef MEEGO_EDITION_HARMATTAN
    QGLFormat format = QGLFormat::defaultFormat();
    format.setSampleBuffers(false);
    format.setSwapInterval(1);
    QGLWidget* glWidget = new QGLWidget(format);
    glWidget->setAutoFillBackground(false);
    view.setViewport(glWidget);
    PagePixmapProvider *pagePixmapProvider = new PagePixmapProvider(glWidget);
#else
    PagePixmapProvider *pagePixmapProvider = new PagePixmapProvider(&view);
#endif

#ifndef MEEGO_EDITION_HARMATTAN
    view.engine()->addImportPath(IMPORT_PATH);
#endif
    view.engine()->addImageProvider("pagepixmapprovider", pagePixmapProvider);
    view.engine()->setNetworkAccessManagerFactory(new NetworkAccessManagerFactory());
//    view.rootContext()->setContextProperty("QUERY_MANAGER", &queryManager);
    view.rootContext()->setContextProperty("LOGIN_MANAGER", &loginManager);
    view.rootContext()->setContextProperty("TOKEN_MANAGER", &tokenManager);
//    view.rootContext()->setContextProperty("POST_UPDATE_RELAY", &postUpdateRelay);
    view.rootContext()->setContextProperty("ME", &me);
    view.rootContext()->setContextProperty("DATA_PATH", DATA_PATH);
    view.rootContext()->setContextProperty("FACEBOOK_PAGE", FACEBOOK_PAGE);
    view.rootContext()->setContextProperty("PAYPAL_DONATE", PAYPAL_DONATE);
    view.rootContext()->setContextProperty("VERSION_MAJOR", QString::number(VERSION_MAJOR));
    view.rootContext()->setContextProperty("VERSION_MINOR", QString::number(VERSION_MINOR));
    view.rootContext()->setContextProperty("VERSION_PATCH", QString::number(VERSION_PATCH));

    // Friends specific
    QString clientId;
    QPluginLoader pluginLoader (CLIENT_ID_PLUGIN);
    if (pluginLoader.load()) {
        QObject *plugin = pluginLoader.instance();
        Interface *castedPlugin = qobject_cast<Interface *>(plugin);
        if (castedPlugin) {
            clientId = castedPlugin->clientId();
            qDebug() << "Client id loaded";
        }
    }

    if (clientId.isEmpty()) {
        if (app.arguments().count() == 2) {
            clientId = app.arguments().at(1);
        } else {
            qDebug() << "Failed to find the client id";
            return -1;
        }
    }
    view.rootContext()->setContextProperty("CLIENT_ID", clientId);
    // End Friends specific

    view.setSource(QUrl(MAIN_QML_FILE));
    view.showFullScreen();
    QObject::connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));

    return app.exec();
}
コード例 #17
0
/**
 * @brief Avr_Core_Builder::loadCore Loads the core described by the configuration file at the path mmcu
 * @param mmcu The path for the configuration file
 * @return
 */
Avr_Core* Avr_Core_Builder::loadCore(QString mmcu){
    //Loader to open plugins
    QPluginLoader loader;
    core = new Avr_Core();
    //Setup the Basics
    core->setMemory(new Avr_Memory);
    core->setRegisters(new Avr_Registers);

    //Load Configuration File
    string line;string id;string setting;

    QString path = PLUGIN_PATH + mmcu;
    ifstream configFile;
    configFile.open(path.toStdString().c_str());

    if (configFile.is_open()){
        //Process config file, there might be a problem
        //with the loop termination here
        while (!configFile.eof()){
            configFile >> line;
            if (line == "END"){
                break;
            }

            if (line[0]==';'){
                //Line is a comment skip
                continue;
            }
            int i = line.find(':');
            id = line.substr(0,i);
            setting = line.substr(i + 1, line.size() - i - 1);
            if (id == "RAMSIZE"){
                qDebug() << "Load Ram\n";
                core->mem->initRam(sizeToInt(setting) + 0xff);
                core->reg->setRam(core->mem->getRam());
				core->reg->setRamEnd(core->mem->getRamEnd());
            }else if (id == "FLASHSIZE"){
                qDebug() << "Load Flash\n";
                core->setFlash(new Avr_Flash(sizeToInt(setting)));

            }else if (id == "EPROMSIZE"){
                qDebug() << "Load Eprom\n";
                core->mem->initEprom(sizeToInt(setting));

            }else if (id == "SPL"){
                qDebug() << "Set SPL\n";
                core->reg->setStackPL(getRegPtr(setting));

            }else if (id == "SPH"){
                qDebug() << "Set SPH\n";
                core->reg->setStackPH(getRegPtr(setting));

            }else if (id == "SREG"){
                core->reg->setSREGP(getRegPtr(setting));

            }else if (id == "PLUGINLIB"){

                qDebug() << "Load Plugin " << QString(setting.c_str()) << "\n";
                loader.setFileName(PLUGIN_PATH + QString(setting.c_str()));
                loader.load();

                QObject *plugin = loader.instance();

                Avr_Hardware_Interface *h = qobject_cast<Avr_Hardware_Interface*>(plugin);

                //Attach all registers
                h->attachRegister(core->reg);

                //Load Registers for the plugin
                //this loads specific registers for specific roles
                for (int j = 0; j < h->getRegisterCount();j++){
                    configFile >> line;
                    if (line[0]==';'){
                        j -= 1;
                        continue;
                    }
                    i = line.find(':');
                    id = line.substr(0,i);
                    setting = line.substr(i + 1, line.size() - i - 1);
                    qDebug() << "Setting " << QString(setting.c_str()) << "\n";
                    h->bindRegister(QString(id.c_str()),getRegPtr(setting));
                   //h->bindRegister(QString(id.c_str()),getRegLoc(setting));
                }
                //Load Interrupts

                core->hardware.push_back(h);
            }else if (id == "INTERFACE"){
                loader.setFileName(QString(setting.c_str()));
                loader.load();
                QList <QObject*> objects = loader.staticInstances();
                if (loader.isLoaded()){
                    std::cout << "Loaded\n";
                }else{
                    std::cout << "Object Count " << objects.size() <<"\n";
                }
                QObject *plugin = loader.instance();
                //Set the Interface;
                this->interface = qobject_cast<Avr_Hardware_Interface*>(plugin);
            }
        }
コード例 #18
0
ファイル: PluginManager.cpp プロジェクト: helandre/Envision
void PluginManager::loadAllPlugins(EnvisionManager& envisionManager)
{
	int lastCountLoaded = -1;

	// Holds the ids of plugins which are not yet loaded.
	QStringList plugins;
	for (auto p_meta : pluginMetaData)
		plugins.append(p_meta.id);

	QTextStream out(stdout);

	while ( lastCountLoaded != loadedPlugins.length() && loadedPlugins.length() < pluginMetaData.length() )
	{
		lastCountLoaded = loadedPlugins.length();

		for (int i = plugins.length() - 1; i >= 0; i--)
		{
			QList<PluginDependency> depList = idToMetaDataMap.value(plugins.at(i))->dependencies;

			bool allDependenciesLoaded = true;
			for (QList<PluginDependency>::iterator dep = depList.begin(); dep != depList.end(); dep++)
			{
				// Check if this dependency is already loaded
				if ( idToPluginLoaderMap.contains(dep->id) == false )
				{
					allDependenciesLoaded = false;
					break;
				}

				// Check if the version of the non-dependent plugin matches the version the current plugin depends on
				if ( !idToMetaDataMap.value(dep->id)->version.startsWith(dep->majorVersion + ".", Qt::CaseSensitive) )
					throw EnvisionException("Plugin " + plugins.at(i) + " depends on version " + dep->majorVersion
							+ " of " + dep->id + " but a different version is installed.");
			}

			if ( allDependenciesLoaded )
			{
				out << "Loading plug-in " << plugins.at(i) << "... " << endl;

				QPluginLoader* plugin = new QPluginLoader(pluginsDir.absoluteFilePath(getLibraryFileName(plugins.at(i))));
				plugin->setLoadHints(QLibrary::ExportExternalSymbolsHint);

				plugin->load();

				if ( plugin->isLoaded() == false )
					throw EnvisionException("Could not load plugin: " + plugin->errorString());

				EnvisionPlugin* p = qobject_cast<EnvisionPlugin*> (plugin->instance());
				p->initialize(envisionManager);

				out << plugins.at(i) << " loaded OK" << endl;

				loadedPlugins.append(plugin);
				idToPluginLoaderMap.insert(plugins.at(i), plugin);
				plugins.removeAt(i);
			}
		}
	}

	// Check if there are any plug-ins with unmet dependencies
	if (plugins.size() > 0)
	{
		out<< "Warning: The following plug-ins have not been loaded because their dependencies are not satisfied" << endl;
		for (int i = 0; i< plugins.size(); ++i) out << "  " << plugins.at(i) << endl;
	}
	else out << "All plug-ins loaded." << endl;
}
コード例 #19
0
void tst_QPluginLoader::errorString()
{
#if defined(Q_OS_WINCE)
    // On WinCE we need an QCoreApplication object for current dir
    int argc = 0;
    QCoreApplication app(argc,0);
#endif
    const QString unknown(QLatin1String("Unknown error"));

    {
    QPluginLoader loader; // default constructed
    bool loaded = loader.load();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(loaded, false);
    QCOMPARE(loader.errorString(), unknown);

    QObject *obj = loader.instance();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(obj, static_cast<QObject*>(0));
    QCOMPARE(loader.errorString(), unknown);

    bool unloaded = loader.unload();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(unloaded, false);
    QCOMPARE(loader.errorString(), unknown);
    }
    {
    QPluginLoader loader( sys_qualifiedLibraryName("tst_qpluginloaderlib"));     //not a plugin
    bool loaded = loader.load();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(loaded, false);
    QVERIFY(loader.errorString() != unknown);

    QObject *obj = loader.instance();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(obj, static_cast<QObject*>(0));
    QVERIFY(loader.errorString() != unknown);

    bool unloaded = loader.unload();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(unloaded, false);
    QVERIFY(loader.errorString() != unknown);
    }

    {
    QPluginLoader loader( sys_qualifiedLibraryName("nosuchfile"));     //not a file
    bool loaded = loader.load();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(loaded, false);
    QVERIFY(loader.errorString() != unknown);

    QObject *obj = loader.instance();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(obj, static_cast<QObject*>(0));
    QVERIFY(loader.errorString() != unknown);

    bool unloaded = loader.unload();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(unloaded, false);
    QVERIFY(loader.errorString() != unknown);
    }

#if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined Q_OS_HPUX && !defined Q_OS_SYMBIAN && !defined Q_OS_QNX
    {
    QPluginLoader loader( sys_qualifiedLibraryName("almostplugin"));     //a plugin with unresolved symbols
    loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
    QCOMPARE(loader.load(), false);
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QVERIFY(loader.errorString() != unknown);

    QCOMPARE(loader.instance(), static_cast<QObject*>(0));
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QVERIFY(loader.errorString() != unknown);

    QCOMPARE(loader.unload(), false);
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QVERIFY(loader.errorString() != unknown);
    }
#endif

    {
    QPluginLoader loader( sys_qualifiedLibraryName("theplugin"));     //a plugin
    QCOMPARE(loader.load(), true);
    QCOMPARE(loader.errorString(), unknown);

    QVERIFY(loader.instance() !=  static_cast<QObject*>(0));
    QCOMPARE(loader.errorString(), unknown);

    // Make sure that plugin really works
    PluginInterface* theplugin = qobject_cast<PluginInterface*>(loader.instance());
    QString pluginName = theplugin->pluginName();
    QCOMPARE(pluginName, QLatin1String("Plugin ok"));

    QCOMPARE(loader.unload(), true);
    QCOMPARE(loader.errorString(), unknown);
    }
}
コード例 #20
0
/*!
 * This function will do the basic loading/unloading tests on the applet.
 */
void
Ft_AppletLoader::DoAppletTest (const char *soname, bool hasBrief)
{
    QPluginLoader loader;

    loader.setFileName (QString (APPLET_PATH) + QString (soname));
    loader.setLoadHints (QLibrary::ResolveAllSymbolsHint);

    /*
     * Getting the DcpAppletIf applet interface object. Checking if the applet
     * loaded, the type of the applet interface is right.
     */
    QVERIFY2 (loader.load (), qPrintable (loader.errorString ()));

    DcpAppletIf *applet = qobject_cast<DcpAppletIf *>(loader.instance ());

    QVERIFY (applet != 0);

    /*
     * Do initialization... in the same way how controlpanel doing:
     */
    applet->init ();

#ifndef TEST_NEW_TITLE_METHODS
    QVERIFY (! applet->title ().isEmpty ());
#endif

    /*
     * Checking if the applet brief is constructed.
     */
    DcpBrief *brief = applet->constructBrief ();
    if (hasBrief)
    {
        QVERIFY2(brief, 
		    "Error when creating brief widget");
#ifdef TEST_NEW_TITLE_METHODS
        /*
         * Checking if the applet has a non-empty title string.
         */
        QVERIFY (! brief->titleText ().isEmpty ());
#endif
    }
    else
        QVERIFY2(!brief, 
		    "This applet should not have a Brief");

    /*
     * Checking if the the main view (the applet widget) is constructed. FIXME:
     * We should call the getMainWidgetId here, but I'm not sure how it is done
     * after the refactoring.
     */
    DcpWidget *widget = applet->constructWidget (0);
    QVERIFY2 (widget, "Error when creating applet's main widget");

#ifdef TEST_NEW_TITLE_METHODS
    /*
     * Check if the applet widget has a non-empty title string.
     */
    QVERIFY (! widget->title ().isEmpty ());
#endif

    QTest::qWait (1000);

//    loader.unload ();
//    delete widget;
//    delete brief;
}