Hi All,
I have created a custom widget, e.i, a label with a clicked() signal. It is properly showing in Qt Designer and I was able to add it on my project UI. The problem is during the compilation of my project, the following error occurred:
release
/employeeentry.
o:employeeentry.
cpp:(.
text$_ZN16Ui_EmployeeEntry7setupUiEP7QDialog
[Ui_EmployeeEntry
::setupUi(QDialog*)]+0x3f1
): undefined reference to `_imp___ZN7HSLabelC1EP7QWidget
'
release/employeeentry.o:employeeentry.cpp:(.text$_ZN16Ui_EmployeeEntry7setupUiEP7QDialog[Ui_EmployeeEntry::setupUi(QDialog*)]+0x3f1): undefined reference to `_imp___ZN7HSLabelC1EP7QWidget'
To copy to clipboard, switch view to plain text mode
Below are the codes of my custom label plugin:
HSLabel.pro
CONFIG += designer plugin
TARGET = $$qtLibraryTarget($$TARGET)
TEMPLATE = lib
QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
CONFIG += release
HEADERS += \
hslabel.h \
customwidgetplugin.h
SOURCES += \
hslabel.cpp \
customwidgetplugin.cpp
target.path = $$[QT_INSTALL_PLUGINS]/designer
sources.files = $$SOURCES $$HEADERS *.pro
sources.path ="D:\Qt\HSLabel"
INSTALLS += target sources
CONFIG += designer plugin
TARGET = $$qtLibraryTarget($$TARGET)
TEMPLATE = lib
QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
CONFIG += release
HEADERS += \
hslabel.h \
customwidgetplugin.h
SOURCES += \
hslabel.cpp \
customwidgetplugin.cpp
target.path = $$[QT_INSTALL_PLUGINS]/designer
sources.files = $$SOURCES $$HEADERS *.pro
sources.path ="D:\Qt\HSLabel"
INSTALLS += target sources
To copy to clipboard, switch view to plain text mode
customwidgetplugin.cpp
#include "hslabel.h"
#include "customwidgetplugin.h"
#include <QtPlugin>
HSLabelPlugin
::HSLabelPlugin(QObject *parent
){
initialized = false;
}
{
if (initialized)
return;
initialized = true;
}
bool HSLabelPlugin::isInitialized() const
{
return initialized;
}
{
return new HSLabel(parent);
}
QString HSLabelPlugin
::name() const {
return "HSLabel";
}
QString HSLabelPlugin
::group() const {
return "Display Widgets";
}
QIcon HSLabelPlugin
::icon() const {
}
QString HSLabelPlugin
::toolTip() const {
return "";
}
QString HSLabelPlugin
::whatsThis() const {
return "";
}
bool HSLabelPlugin::isContainer() const
{
return false;
}
QString HSLabelPlugin
::domXml() const {
return "<ui language=\"c++\">\n"
" <widget class=\"HSLabel\" name=\"hsLabel\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>50</width>\n"
" <height>13</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"text\" >\n"
" <string>HSLabel</string>\n"
" </property>\n"
" </widget>\n"
"</ui>\n";
}
QString HSLabelPlugin
::includeFile() const {
return "hslabel.h";
}
Q_EXPORT_PLUGIN2(customwidgetplugin, HSLabelPlugin)
#include "hslabel.h"
#include "customwidgetplugin.h"
#include <QtPlugin>
HSLabelPlugin::HSLabelPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}
void HSLabelPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
if (initialized)
return;
initialized = true;
}
bool HSLabelPlugin::isInitialized() const
{
return initialized;
}
QWidget *HSLabelPlugin::createWidget(QWidget *parent)
{
return new HSLabel(parent);
}
QString HSLabelPlugin::name() const
{
return "HSLabel";
}
QString HSLabelPlugin::group() const
{
return "Display Widgets";
}
QIcon HSLabelPlugin::icon() const
{
return QIcon();
}
QString HSLabelPlugin::toolTip() const
{
return "";
}
QString HSLabelPlugin::whatsThis() const
{
return "";
}
bool HSLabelPlugin::isContainer() const
{
return false;
}
QString HSLabelPlugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"HSLabel\" name=\"hsLabel\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>50</width>\n"
" <height>13</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"text\" >\n"
" <string>HSLabel</string>\n"
" </property>\n"
" </widget>\n"
"</ui>\n";
}
QString HSLabelPlugin::includeFile() const
{
return "hslabel.h";
}
Q_EXPORT_PLUGIN2(customwidgetplugin, HSLabelPlugin)
To copy to clipboard, switch view to plain text mode
customwidgetplugin.h
#ifndef CUSTOMWIDGETPLUGIN_H
#define CUSTOMWIDGETPLUGIN_H
#include <QDesignerCustomWidgetInterface>
{
Q_OBJECT
public:
HSLabelPlugin
(QObject *parent
= 0);
bool isContainer() const;
bool isInitialized() const;
private:
bool initialized;
};
#endif
#ifndef CUSTOMWIDGETPLUGIN_H
#define CUSTOMWIDGETPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class HSLabelPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
HSLabelPlugin(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;
};
#endif
To copy to clipboard, switch view to plain text mode
hslabel.cpp
#include <QtGui>
#include <QDebug>
#include "hslabel.h"
{
qDebug() << "HSLabel Constructor";
}
{
qDebug() << "HSLabel Pressed";
emit clicked();
}
#include <QtGui>
#include <QDebug>
#include "hslabel.h"
HSLabel::HSLabel(QWidget *parent)
: QLabel(parent)
{
qDebug() << "HSLabel Constructor";
}
void HSLabel::mousePressEvent ( QMouseEvent * ev )
{
qDebug() << "HSLabel Pressed";
emit clicked();
}
To copy to clipboard, switch view to plain text mode
hslabel.h
#include <QtGui>
#include <QDebug>
#include "hslabel.h"
{
qDebug() << "HSLabel Constructor";
}
{
qDebug() << "HSLabel Pressed";
emit clicked();
}
#include <QtGui>
#include <QDebug>
#include "hslabel.h"
HSLabel::HSLabel(QWidget *parent)
: QLabel(parent)
{
qDebug() << "HSLabel Constructor";
}
void HSLabel::mousePressEvent ( QMouseEvent * ev )
{
qDebug() << "HSLabel Pressed";
emit clicked();
}
To copy to clipboard, switch view to plain text mode
Please help, I'm stuck here.. Thanks..
Bookmarks