Results 1 to 3 of 3

Thread: Problem in using Custom Widget

  1. #1
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Problem in using Custom Widget

    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:

    Qt Code:
    1. 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

    Qt Code:
    1. CONFIG += designer plugin
    2. TARGET = $$qtLibraryTarget($$TARGET)
    3. TEMPLATE = lib
    4. QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
    5.  
    6. CONFIG += release
    7. HEADERS += \
    8. hslabel.h \
    9. customwidgetplugin.h
    10.  
    11. SOURCES += \
    12. hslabel.cpp \
    13. customwidgetplugin.cpp
    14.  
    15. target.path = $$[QT_INSTALL_PLUGINS]/designer
    16. sources.files = $$SOURCES $$HEADERS *.pro
    17. sources.path ="D:\Qt\HSLabel"
    18. INSTALLS += target sources
    To copy to clipboard, switch view to plain text mode 

    customwidgetplugin.cpp

    Qt Code:
    1. #include "hslabel.h"
    2. #include "customwidgetplugin.h"
    3. #include <QtPlugin>
    4.  
    5. HSLabelPlugin::HSLabelPlugin(QObject *parent)
    6. : QObject(parent)
    7. {
    8. initialized = false;
    9. }
    10.  
    11. void HSLabelPlugin::initialize(QDesignerFormEditorInterface * /* core */)
    12. {
    13. if (initialized)
    14. return;
    15.  
    16. initialized = true;
    17. }
    18.  
    19. bool HSLabelPlugin::isInitialized() const
    20. {
    21. return initialized;
    22. }
    23.  
    24. QWidget *HSLabelPlugin::createWidget(QWidget *parent)
    25. {
    26. return new HSLabel(parent);
    27. }
    28.  
    29. QString HSLabelPlugin::name() const
    30. {
    31. return "HSLabel";
    32. }
    33.  
    34. QString HSLabelPlugin::group() const
    35. {
    36. return "Display Widgets";
    37. }
    38.  
    39. QIcon HSLabelPlugin::icon() const
    40. {
    41. return QIcon();
    42. }
    43.  
    44. QString HSLabelPlugin::toolTip() const
    45. {
    46. return "";
    47. }
    48.  
    49. QString HSLabelPlugin::whatsThis() const
    50. {
    51. return "";
    52. }
    53.  
    54. bool HSLabelPlugin::isContainer() const
    55. {
    56. return false;
    57. }
    58.  
    59. QString HSLabelPlugin::domXml() const
    60. {
    61. return "<ui language=\"c++\">\n"
    62. " <widget class=\"HSLabel\" name=\"hsLabel\">\n"
    63. " <property name=\"geometry\">\n"
    64. " <rect>\n"
    65. " <x>0</x>\n"
    66. " <y>0</y>\n"
    67. " <width>50</width>\n"
    68. " <height>13</height>\n"
    69. " </rect>\n"
    70. " </property>\n"
    71. " <property name=\"text\" >\n"
    72. " <string>HSLabel</string>\n"
    73. " </property>\n"
    74. " </widget>\n"
    75. "</ui>\n";
    76. }
    77.  
    78. QString HSLabelPlugin::includeFile() const
    79. {
    80. return "hslabel.h";
    81. }
    82.  
    83. Q_EXPORT_PLUGIN2(customwidgetplugin, HSLabelPlugin)
    To copy to clipboard, switch view to plain text mode 

    customwidgetplugin.h
    Qt Code:
    1. #ifndef CUSTOMWIDGETPLUGIN_H
    2. #define CUSTOMWIDGETPLUGIN_H
    3.  
    4. #include <QDesignerCustomWidgetInterface>
    5.  
    6. class HSLabelPlugin : public QObject, public QDesignerCustomWidgetInterface
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. HSLabelPlugin(QObject *parent = 0);
    12.  
    13. bool isContainer() const;
    14. bool isInitialized() const;
    15. QIcon icon() const;
    16. QString domXml() const;
    17. QString group() const;
    18. QString includeFile() const;
    19. QString name() const;
    20. QString toolTip() const;
    21. QString whatsThis() const;
    22. QWidget *createWidget(QWidget *parent);
    23. void initialize(QDesignerFormEditorInterface *core);
    24.  
    25. private:
    26. bool initialized;
    27. };
    28.  
    29. #endif
    To copy to clipboard, switch view to plain text mode 

    hslabel.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3. #include "hslabel.h"
    4.  
    5. HSLabel::HSLabel(QWidget *parent)
    6. : QLabel(parent)
    7. {
    8. qDebug() << "HSLabel Constructor";
    9.  
    10. }
    11.  
    12. void HSLabel::mousePressEvent ( QMouseEvent * ev )
    13. {
    14. qDebug() << "HSLabel Pressed";
    15. emit clicked();
    16. }
    To copy to clipboard, switch view to plain text mode 

    hslabel.h
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3. #include "hslabel.h"
    4.  
    5. HSLabel::HSLabel(QWidget *parent)
    6. : QLabel(parent)
    7. {
    8. qDebug() << "HSLabel Constructor";
    9.  
    10. }
    11.  
    12. void HSLabel::mousePressEvent ( QMouseEvent * ev )
    13. {
    14. qDebug() << "HSLabel Pressed";
    15. emit clicked();
    16. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem in using Custom Widget

    I think you need to link to the widget too, not just include the source code.

  3. The following user says thank you to tbscope for this useful post:

    cutie.monkey (13th February 2011)

  4. #3
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in using Custom Widget

    Thanks, its working now. Cheers!

Similar Threads

  1. Problem with custom container widget
    By MrGarbage in forum Qt Tools
    Replies: 4
    Last Post: 25th August 2007, 03:37
  2. Replies: 1
    Last Post: 25th October 2006, 15:41
  3. Custom widget problem
    By chombium in forum Qt Programming
    Replies: 1
    Last Post: 27th September 2006, 16:41
  4. Replies: 3
    Last Post: 12th April 2006, 08:20
  5. Problem with custom widget
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 11:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.