there is question that can I implement a custom plugin that the QUiLoader
can load it? actually I know QDesignerCustomWidgetInterface class can reach this
goal. but it likes big :I wantn't use my custom by designer or more,this is my example:
customInterface.h---
class QWidget;
class QString;
class CustomInterface
{
public:
virtual ~CustomInterface() {}
virtual QString name() const = 0;
virtual QWidget *createWidget(QWidget *parent) = 0;
};
Q_DECLARE_INTERFACE(CustomInterface, "com.
www.custonminterface")
weatherPlugin.h----
#ifndef WEATHERPLUGIN_H_
#define WEATHERPLUGIN_H_
#include <QtGui>
#include "customInterface.h"
class WeatherPlugin : public QObject, public CustomInterface
{
Q_OBJECT
Q_INTERFACES(CustomInterface)
public:
WeatherPlugin(QObject *parent = 0);
bool isInitialized() const;
QString name() const;
QWidget *createWidget(QWidget *parent);
private:
bool initialized;
};
#endif /*WEATHERPLUGIN_H_*/
weatherPlugin.cpp----
#include "../Header/weatherPlugin.h"
#include "../Header/Weather.h"
#include <QtPlugin>
WeatherPlugin::WeatherPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}
bool WeatherPlugin::isInitialized() const
{
return initialized;
}
QWidget *WeatherPlugin::createWidget(QWidget *parent)
{
return new Weather(parent);
}
QString WeatherPlugin::name() const
{
return "Weather";
}
Q_EXPORT_PLUGIN2(Weather, WeatherPlugin)
Weather.h---
class Weather : public QWidget
{
Q_OBJECT
public:
Weather(QWidget *parent = 0){};
~Weather(){};
};
main.cpp
#include <QtGui>
#include <QUiLoader>
#include <QDebug>
int main(int argc,char **argv)
{
QApplication app(argc, argv);
QWidget *man=NULL;
QUiLoader *lo=new QUiLoader;
lo->addPluginPath("./ddd");//the dir I have test for other dll implement by QDesignerCustomWidgetInterface it's right.
qDebug()<<lo->availableWidgets ()<<"--------"<<lo->availableWidgets ().count()<<lo->pluginPaths () ;
man=lo->createWidget("Weather");
man->show();
return app.exec();
}
.is there some other way to implement my idea?