#include <QtCore>#include "../pluginInterface.h"class testPlugin : public QObject, public pluginInterface{ Q_OBJECT Q_INTERFACES(pluginInterface)public: QString getAuthor() { return "zodiac"; }};
#include "test_plugin.h"Q_EXPORT_PLUGIN2(testplugin, testPlugin);
#include "cryptMain.h"#include "pluginInterface.h"#include <QtGui>#include <QMessageBox>cryptMain::cryptMain(QWidget *parent) : QMainWindow(parent){ setupUi(this); pluginsDir = QDir(qApp->applicationDirPath()); pluginsDir.cd("plugins"); foreach (pluginFileName, pluginsDir.entryList(QDir::Files)) { QPluginLoader loader(pluginsDir.absoluteFilePath(pluginFileName)); plugin = loader.instance(); /*if (loader.isLoaded()) { pluginInterface *plg = qobject_cast<pluginInterface *>(plugin); QMessageBox::information(0, "!!!", plg->getAuthor()); }*/ QMessageBox::information(0, "!!!", loader.errorString()); } /*QPluginLoader loader("plugins/libtest_plugin.so"); if (!loader.load()) { QMessageBox::information(0, "!!!", loader.errorString()); }*/}
#include <QPluginLoader>#include <QMessageBox>#include <QDir>#include "ui_cryptMain.h"class cryptMain : public QMainWindow, private Ui::cryptMain{ Q_OBJECTpublic: cryptMain(QWidget *parent = 0);private slots:private: QObject *plugin; //QPluginLoader loader; QDir pluginsDir; QString pluginFileName;};
#include <QApplication>#include "pluginInterface.h"#include "cryptMain.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); cryptMain form; form.show(); return app.exec();}
####################################################################### Automatically generated by qmake (2.01a) Thu Feb 21 18:17:20 2008######################################################################TEMPLATE = appTARGET = DEPENDPATH += .INCLUDEPATH += .# InputHEADERS += cryptMain.hFORMS += cryptMain.uiSOURCES += cryptMain.cpp main.cpp
#include <QObject>#include <QtCore>#include <QString>class pluginInterface{public: virtual ~pluginInterface() {} virtual QString getAuthor() = 0;};Q_DECLARE_INTERFACE (pluginInterface, "zodiac.pluginInterface/1.0")
####################################################################### Automatically generated by qmake (2.01a) Wed Feb 27 14:45:38 2008######################################################################TEMPLATE = libCONFIG += pluginTARGET = DEPENDPATH += .INCLUDEPATH += .# InputHEADERS += test_plugin.h ../pluginInterface.hSOURCES += test_plugin.cpp
#include "pluginInterface.h "int main(int argc, char *argv[]){ QApplication app(argc, argv); QPluginLoader loader("plugins/debug/testd.dll"); QObject *plugin = loader.instance(); if(plugin) { pluginInterface *plg = qobject_cast<pluginInterface *>(plugin); if(plg) QMessageBox::information(0, "!!!", plg->getAuthor()); else QMessageBox::information(0, "error", "qobject_cast fail"); } else QMessageBox::information(0, "error", loader.errorString ()); return 0;