[SOLVED]Qt Plugin framework, extend with C++



  • Hi!

    I'm looking over plugin framework, and searching for a way how can I extend a program with plugins written in C++ with "full" control over a program ( simple example: add a new dialog and menu item, then execute that dialog when triggered)
    How has Qt Creator implemented it's functionality with plugins?
    I googled around and looked "here":http://doc.qt.digia.com/qt/plugins-howto.html , but I didn't found what I was looking for.

    Can someone point me in the right direction.

    Regards,
    Jake



  • Hey,
    actually, the link you posted contains some useful information - but you need to look in the section "The Lower-Level API: Extending Qt Applications".

    Now, when working with plugins, Qt 5 brings some cleaned up interface, so I recommend using that, but if you can't, it works almost the same in Qt 4, just some different macros.

    What you should look at is this example, which implements a plugin interface:
    "http://qt-project.org/doc/qt-5.0/qtwidgets/tools-plugandpaint.html":http://qt-project.org/doc/qt-5.0/qtwidgets/tools-plugandpaint.html

    However, with this aproach you're not giving full control over your application to your plugins, because your plugins can only use classes that are provided by some form of shared library - and the interface class of course.
    For example, you can use all of Qt's functions and classes, because both, your application and your plugin, will be linked against the Qt library.
    However, your custom classes, like your MainWindow, are not provided by any shared library but only available your executable.
    To enable your plugin to access those classes, I think (and I'm not entirely sure about this, but this was the only way I was able to achieve something like that) you have to outsource the entire application logic into a shared library and link your plugins against it.

    That may sound complicated, but it actually is not at all - just compile your classes into a library and your actual programm will only contain the main function which creates an instance of your main window (and uses the library itself). Then your plugins can link against those libraries.

    What you could also do is create a set of abstract classes and provide those as library, but if you truly wann FULL control, I guess you have to go with the approach described above.

    PS: I guess most of the times, you don't need/want to give your plugins full control over your application but only provide a subset of functions, so you should consider what way makes more sense...



  • Hi!

    Thanks for clearing things up.
    Currently I'm still on Qt 4.8.3 because I need MinGW compiler ( to lazy to find replacement for unistd.h which VS does not support). But I'm porting to Qt 5.

    Full control of course is not an option. I did not find suitable words to express myself what I want.

    I'm currently still planing how I'll implement everything so that there wont be any problems with extensibility. Overall, I solved a lot of problems with some basic logic with combination of XML and Lua ( not QtLua).

    Thanks!
    Marked as solved.

    Regards,
    Jake


Log in to reply
 

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