2

I was just reading up about QWidgets and I would like to create plugins that are widgets which will be loaded during runtime. When I was looking at the sample code and the requirements, the plugin seems to inherit from the interface and QObject. How would I create QWidget-plugins where they all have different buttons and different slots? Also, would it be possible to create a plugin that inherits from the interface and a baseclass that inherits from QWidget(that inherits from QObject).

http://developer.qt.nokia.com/doc/qt-4.8/plugins-howto.html

However, I read about metaobject where you can load widgets during runtime, just by knowing their names (doesn't require RTTI support). But exactly how would I delived the classes to the porject for it to recognize them? Whn dealing with plugins I need to have them in a special project that I compile with a different sets of flags in the .pro file. But how would I do it here?

I would really like to use the qtplugin but how?

An Idea:

Would it be acceptable and optimal to let the plugin create a QWidget that it returns? Don't really see the point of writing plugins to the designer if I create my interface without it. Or have I misunderstood it?

http://techbase.kde.org/Development/Tutorials/Writing_Qt_Designer_Plugins

class workspaceInterface {
   virtual QWidget* createWorkspace(QWidget* parent);
   ... other useful functions...
}

class mySpecialWidget : public QWidget {
    mySpecialWidget {
        add a layout, add some buttons, maybe change the color
    }
}

//plugin
#include "myspecialwidget.h"

class myPlugin : public QObject, public workspaceInterface {
    QWidget* createWorkspace(QWidget* parent) {
        return new MySpecialWidget();
    }
    .... 
}

All of this code I would put in one project, compile it as a plugin and then look for it in my main application and load it in. The I would create a instance of it and let it create a widget that I will display.

Is there any better way of doing this, or is this it?

chikuba
  • 4,229
  • 6
  • 43
  • 75

1 Answers1

0

You may be looking for Creating Custom Widgets for Qt Designer. Widget plug-ins do inherit from QWidget. For example, see World Time Clock Plugin.

While widget plug-ins are intended mostly for Qt Designer, some of their functionality can be used during runtime with the help of QUiLoader.

Edit:

It is definitely some investment to write Qt Designer plug-ins. If you do not need design time support, you may find little value in creating them.

For your own plug-in infrastructure you can package plug-ins in a set of dynamic libraries with standardized API (export functions) to invoke them.

Dmitry Shkuropatsky
  • 3,902
  • 2
  • 21
  • 13
  • That the thing, im not looking to create plugins for the designer. Couldnt care less if people used my special widget. The thing I want is to be able to load in widgets during runtime using their plugin mechanism. – chikuba Feb 10 '12 at 02:16
  • Do you need to create widgets from .ui files or just from their names? – Dmitry Shkuropatsky Feb 10 '12 at 02:28
  • dont think i have any ui files. all my widgets are just h/cpp files where eveything is created through code. thinking about making a plugin-object with a function that creates the widget and just put my specialized widget in the same project. would that be ugly? – chikuba Feb 10 '12 at 03:21
  • That should be ok. If you have not already seen this, check [the Lower-Level API: Extending Qt Applications](http://doc.qt.nokia.com/4.8-snapshot/plugins-howto.html#the-lower-level-api-extending-qt-applications). – Dmitry Shkuropatsky Feb 10 '12 at 04:17
  • I would like to see an answer to this question. – KcFnMi Jul 28 '16 at 00:04