cplugin.cpp cplugin.h QObject #include"cplugin.h" #include<QObject> cPlugin::cPlugin(constQString&szFile): m_lpPluginLoader(0), m_lpImportInterface(0), m_lpAction(0) { m_lpPluginLoader=newQPluginLoader(szFile); if(!m_lpPluginLoader) return; if(!m_lpPluginLoader->load()) { deletem_lpPluginLoader; m_lpPluginLoader=0; return; } QObject*lpObject=m_lpPluginLoader->instance(); if(!lpObject) { deletem_lpPluginLoader; m_lpPluginLoader=0; return; } if(!szFile.left(1).compare("i",Qt::CaseInsensitive)) { m_lpImportInterface=qobject_cast<cImportInterface*>(lpObject); if(!m_lpImportInterface) { deletem_lpPluginLoader; m_lpPluginLoader=0; return; } } elseif(!szFile.left(1).compare("d",Qt::CaseInsensitive)) { m_lpDBInterface=qobject_cast<cDBInterface*>(lpObject); if(!m_lpDBInterface) { deletem_lpPluginLoader; m_lpPluginLoader=0; return; } } } cPlugin::~cPlugin() { if(m_lpPluginLoader) deletem_lpPluginLoader; } boolcPlugin::isValid() { return(m_lpPluginLoader!=0); } cPlugin::PluginCapcPlugin::capability() { if(m_lpImportInterface) return(PluginCapImport); elseif(m_lpDBInterface) return(PluginCapDB); return(PluginCapNone); } QStringcPlugin::pluginName() { if(m_lpImportInterface) return(m_lpImportInterface->pluginName()); elseif(m_lpDBInterface) return(m_lpDBInterface->pluginName()); return("noname"); } qint16cPlugin::pluginAPIVersion() { if(m_lpImportInterface) return(m_lpImportInterface->pluginAPIVersion()); elseif(m_lpDBInterface) return(m_lpDBInterface->pluginAPIVersion()); return(0); } qint16cPlugin::pluginVersion() { if(m_lpImportInterface) return(m_lpImportInterface->pluginVersion()); elseif(m_lpDBInterface) return(m_lpDBInterface->pluginVersion()); return(0); } QStringcPlugin::pluginFile() { return(m_lpPluginLoader->fileName()); } voidcPlugin::setAction(QAction*lpAction) { m_lpAction=lpAction; } QAction*cPlugin::action() { return(m_lpAction); } cImportInterface*cPlugin::importInterface() { return(m_lpImportInterface); } cDBInterface*cPlugin::dbInterface() { return(m_lpDBInterface); }