My custom plugin works well using the following code. In this example, the namespace is used not only in the plugin, but also in the class that the plugin inherits.
Header for the plugin --- it can be used in QDesigner
namespace plugin { class MyCustomPlugin: public QObject, public QDesignerCustomWidgetInterface { Q_OBJECT Q_INTERFACES(QDesignerCustomWidgetInterface) public: MyCustomPlugin(QObject *parent = 0); bool isContainer() const; bool isInitialized() const; QIcon icon() const; QString domXml() const; QString group() const; QString includeFile() const; QString name() const; QString toolTip() const; QString whatsThis() const; QWidget *createWidget(QWidget *parent); void initialize(QDesignerFormEditorInterface *core); private: bool initialized; }; }
cpp file for this plugin
Implement the class as usual, but the following methods should consider the namespace:
QString MyCustomPlugin::domXml() const { return "<widget class=\"plugin::MyCustomClass\" name=\"mycustomclass\">\n" ... } QString MyCustomPlugin::name() const { return "plugin::MyCustomClass"; } QWidget *MyCustomPlugin::createWidget(QWidget *parent) { return new plugin::MyCustomClass(parent); } Q_EXPORT_PLUGIN2(mycustomplugin, plugin::MyCustomPlugin)
Mycustomclass
namespace plugin { class QDESIGNER_WIDGET_EXPORT MyCustomClass: public MyCustomPlugin { Q_OBJECT public: MyCustomClass(QWidget * parent = 0) {} }; }
Tarod
source share