我制作了一个自定义小部件“DuwagWidget”和自定义小部件插件“DuwagWidgetPlugin”,可以在 qt 设计器中拖放以创建我的 duwag.ui 文件。
但是,当我尝试编译我的程序时,ui_duwag.h 是从 QT 用户界面编译器生成的,但是在这个自动生成的文件中,uic 不包括我的“DuwagWidget.h”,这是创建自定义小部件类所必需的.
DuwagWidgetPlugin(从 QT 中的 Interface 派生以创建 CustomWidgets)只是 DuwagWidget 的一个工厂类。
这是 DuwagWidgetPlugin 的代码:^
#include <DuwagWidgetPlugin.h>
#include <QtPlugin>
#include <qwidget.h>
#include <MTBFWidget.h>
DuwagWidgetPlugin::DuwagWidgetPlugin( QObject *parent ) : QObject(parent) {
initialized = false;
}
void DuwagWidgetPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (initialized)
return;
initialized = true;
}
bool DuwagWidgetPlugin::isInitialized() const {
return initialized;
}
QWidget *DuwagWidgetPlugin::createWidget(QWidget *parent) {
return new DuwagWidget( parent );
}
QString DuwagWidgetPlugin::name() const {
return "DuwagWidget";
}
QString DuwagWidgetPlugin::group() const {
return "duwagplugin";
}
QIcon DuwagWidgetPlugin::icon() const {
return QIcon();
}
QString DuwagWidgetPlugin::toolTip() const {
return "The duwag control panel";
}
QString DuwagWidgetPlugin::whatsThis() const {
return "The duwag Control panel";
}
bool DuwagWidgetPlugin::isContainer() const {
return false;
}
QString DuwagWidgetPlugin::domXml() const {
return "<widget class=\"DuwagWidget\" name=\"DuwagWidget\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>The MTBF Control panel</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>The MTBF Control panel.</string>\n"
" </property>\n"
"</widget>\n";
}
QString DuwagWidgetPlugin::includeFile() const {
return "DuwagWidget.h";
}
Q_EXPORT_PLUGIN2(duwagplugin, DuwagWidgetPlugin)
所以问题是,在生成的头文件中,它无法制作自定义小部件“DuwagWidget”,因为它不知道它是什么..