class PluginInterface{public: virtual void version(); virtual void path(); virtual void setMainWnd(MainWindow * prmVal);};
class PluginManager{public: explicit PluginManager(); static PluginManager* instance(); void loadPlugins(); void setMainWnd(MainWindow * prmVal);private: QList<PluginInterface *> plugins; MainWindow * mainWnd;private: static PluginManager* _self;};
class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); void echo(); QWebView * view; QWebView * getWebView();};
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ view = new QWebView; view->load(QUrl("http://ya.ru")); setCentralWidget(view); PluginManager * pluginmanager = PluginManager::instance(); pluginmanager->setMainWnd(this); pluginmanager->loadPlugins();}QWebView * MainWindow::getWebView(){ return view;}
gamePlugin = qobject_cast<PluginInterface *>(plugin); if (gamePlugin) { plugins << gamePlugin; gamePlugin->setMainWnd(mainWnd); gamePlugin->version(); QMessageBox::information(0,"Plugin manager",fileName); }
void TestPlugin2::version(){ mainWnd->echo(); // НЕ работает: release/testplugin2.o:testplugin2.cpp::-1: error: undefined reference to `MainWindow::echo()' // QWebView * view = mainWnd->getWebView(); // НЕ работает: release/testplugin2.o:testplugin2.cpp::-1: error: undefined reference to `MainWindow::getWebView()' QWebView * view = mainWnd->view; // РАБОТАЕТ if (view != 0) { view->load(QUrl("http://yandex.ru")); } QMessageBox::information(0,"test plugin 2","version");}
class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); void echo(); MainWindow * self(); QWebView * view; QWebView * getWebView();};