Вобщем ситуация следующая!
Я взял простейший пример по созданию пользовательского виджета.
qclearlineedit.h
#ifndef FILTEREDIT_H
#define FILTEREDIT_H
#include <QVBoxLayout>
#include <QToolButton>
#include <QLineEdit>
class QClearLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit QClearLineEdit(QWidget *parent = 0);
private:
QToolButton *button;
private slots:
void textChanged(QString);
};
#endif // FILTEREDIT_H
qclearlineedit.cpp
#include "qclearlineedit.h"
QClearLineEdit::QClearLineEdit(QWidget *parent) :
QLineEdit(parent)
{
button=new QToolButton(this);
button->setCursor(Qt::ArrowCursor);
button->setGeometry(0,0,15,15);
button->setText("...");
button->setFocusPolicy(Qt::NoFocus);
button->setIcon(QIcon::fromTheme("edit-clear"));
button->show();
button->setStyleSheet("border: none;");
connect(this,SIGNAL(textChanged(QString)),this,SLOT(textChanged(QString)));
connect(button,SIGNAL(clicked()),this,SLOT(clear()));
QVBoxLayout *layout=new QVBoxLayout(this);
layout->addWidget(button,0,Qt::AlignRight);
layout->setSpacing(0);
layout->setMargin(0);
}
void QClearLineEdit::textChanged(QString text)
{
if (text.isEmpty()) button->hide();
else button->show();
}
далее код плагина
qclearlineeditplugin.h
#ifndef QCLEARLINEEDITPLUGIN_H
#define QCLEARLINEEDITPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class QClearLineEditPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
QClearLineEditPlugin(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 m_initialized;
};
#endif
qclearlineeditplugin.cpp
#include "qclearlineedit.h"
#include "qclearlineeditplugin.h"
#include <QtCore/QtPlugin>
QClearLineEditPlugin::QClearLineEditPlugin(QObject *parent)
: QObject(parent)
{
m_initialized = false;
}
void QClearLineEditPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool QClearLineEditPlugin::isInitialized() const
{
return m_initialized;
}
QWidget *QClearLineEditPlugin::createWidget(QWidget *parent)
{
return new QClearLineEdit(parent);
}
QString QClearLineEditPlugin::name() const
{
return QLatin1String("QClearLineEdit");
}
QString QClearLineEditPlugin::group() const
{
return QLatin1String("");
}
QIcon QClearLineEditPlugin::icon() const
{
return QIcon();
}
QString QClearLineEditPlugin::toolTip() const
{
return QLatin1String("");
}
QString QClearLineEditPlugin::whatsThis() const
{
return QLatin1String("");
}
bool QClearLineEditPlugin::isContainer() const
{
return false;
}
QString QClearLineEditPlugin::domXml() const
{
return QLatin1String("<widget class=\"QClearLineEdit\" name=\"qClearLineEdit\">\n</widget>\n");
}
QString QClearLineEditPlugin::includeFile() const
{
return QLatin1String("qclearlineedit.h");
}
Q_EXPORT_PLUGIN2(qclearlineeditplugin, QClearLineEditPlugin)
В результате создается файл qclearlineeditplugin.dll его я копирую в папку C:\Qt\4.7.3\plugins\designer
файлы qclearlineedit.h qclearlineedit.cpp в папку C:\Qt\4.7.3\include\QtGui...
Далее запуская Creator виджет виден. его можно поместить на форму, но вот при компиляции выдает слудющее:
release/mainwindow.o:mainwindow.cpp:(.text$_ZN13Ui_MainWindow7setupUiEP11QMainWindow[Ui_MainWindow::setupUi(QMainWindow*)]+0x129): undefined reference to `QClearLineEdit::QClearLineEdit(QWidget*)'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release/untitled.exe] Error 1
mingw32-make: *** [release] Error 2
У кого какие есть идеи?