Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dynamic Plugin Help

Dynamic Plugin Help

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blizzard
    wrote on last edited by
    #1

    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

    Software Engineer | Aerospace & Defence

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved