Dynamic Plugin Help



  • Hey,

    I have 2 projects, one is a mainwindow and the other is a custom QWidget. I want to build the QWidget project as a plugin, that can be dynamically loaded into my mainwindow project as a subwindow. I read the plugandpaint example in the Qt Docs, but still need a hand.

    Here's what I have so far....

    MAINWINDOW PROJECT (load plugins here):

    mainwindow.cpp
    @void mainwindow::loadPlugins() {

    QDir pluginsDir = QDir(qApp->applicationDirPath());

    #if defined(Q_OS_WIN)
    if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
    pluginsDir.cdUp();
    #elif defined(Q_OS_MAC)
    if (pluginsDir.dirName() == "MacOS") {
    pluginsDir.cdUp();
    pluginsDir.cdUp();
    pluginsDir.cdUp();
    }
    #endif
    pluginsDir.cd("plugins");

    foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
    QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
    QObject *plugin = loader.instance();
    if (plugin) {
    populateTools(plugin);
    pluginFileNames += fileName;
    }
    }
    }

    void mainwindow::populateTools(QObject *plugin) {

    myInterface *myWidget = qobject_cast<myInterface *>(plugin);
    //not sure what to do here, I want to be able to do something like:
    subWindow = myMDI->addSubWindow(myWidget);
    }
    @
    interfaces.h
    @
    #include <QtPlugin>

    class myInterface {

    public:
    virtual ~myInterface();
    // need to add some virtual function(s) here?

    };
    Q_DECLARE_INTERFACE(myInterface, "myInterface-1.0" )
    @

    CUSTOM QWIDGET PROJECT (to be built as a plugin)

    Not sure what to do here besides adding to the .pro file:
    @
    CONFIG += dll
    CONFIG += plugin
    @

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.