PDA

View Full Version : Problem in using Custom Widget



cutie.monkey
13th February 2011, 05:54
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_E mployeeEntry7setupUiEP7QDialog[Ui_EmployeeEntry::setupUi(QDialog*)]+0x3f1): undefined reference to `_imp___ZN7HSLabelC1EP7QWidget'

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


customwidgetplugin.cpp



#include "hslabel.h"
#include "customwidgetplugin.h"
#include <QtPlugin>

HSLabelPlugin::HSLabelPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}

void HSLabelPlugin::initialize(QDesignerFormEditorInter face * /* 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)



customwidgetplugin.h


#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


hslabel.cpp


#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();
}


hslabel.h


#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();
}


Please help, I'm stuck here.. Thanks..:confused:

tbscope
13th February 2011, 07:59
I think you need to link to the widget too, not just include the source code.

cutie.monkey
13th February 2011, 08:28
Thanks, its working now. Cheers!;)