Qt Forum - programming with C++ and Qt
Register Calendar Members List Team Members Search Frequently Asked Questions Go to the Main Page

Qt Forum - programming with C++ and Qt » QtForum.org » Qt » Qt Designer » Why does my plugin widget not show? » Hello Guest [Login|Register]
Last Post | First Unread Post Print Page | Recommend to a Friend | Add Thread to Favorites
Post New Thread Post Reply
Go to the bottom of this page Why does my plugin widget not show?
Author
Post « Previous Thread | Next Thread »
leoclog
Assistant


Registration Date: 10.04.2008
Posts: 5

Level: 6 [?]
Experience: 181
Next Level: 282

101 points of experience needed for next level

Daumen hoch! Why does my plugin widget not show? Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

Hi,
I started using QT4.3 on Linux about 3 months ago and I decided I need a plugin widget containing a LineEdit and a label. Nothing to difficult I thought.

I followed the tutorial and managed to have the plugin show in QT designer, I can drag the plugin widget into the design which shows as I intended it to show. When I do a preview, my custom widget doesn't show on the screen. Same when I compile, the widget won't show on the screen.

In QT designer, when I select my custom widget I get the following message :

A class name mismatch occurred when creating a widget using the custom widget factory registered for widgets of class SelectDateWidget. It returned a widget of class QWidget.

Could someone have a look at the code attached and see what I'm doing wrong?

Nb. After compiling the plugin I copy the generated libselectdatewidget.so to /usr/lib/qt4/plugins/designer.


Thanks,

Leo

customwidgerplugin.h
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
#ifndef CUSTOMWIDGETPLUGIN_H
#define CUSTOMWIDGETPLUGIN_H

#include "selectdatewidget.h"
#include <QDesignerCustomWidgetInterface>

class SelectDateWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface
{
     Q_OBJECT
     Q_INTERFACES(QDesignerCustomWidgetInterface)

   public:
     SelectDateWidgetPlugin(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



customwidgetplugin.cpp
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
#include "selectdatewidget.h"
#include "customwidgetplugin.h"

#include <QtPlugin>

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

void SelectDateWidgetPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
     if (initialized)
        return;

     initialized = true;
}

bool SelectDateWidgetPlugin::isInitialized() const
{
     return initialized;
}

QWidget *SelectDateWidgetPlugin::createWidget(QWidget *parent)
{
        SelectDateWidget *x = new SelectDateWidget(parent);
    return x;
}

QString SelectDateWidgetPlugin::name() const
{
        return "SelectDateWidget";
}

QString SelectDateWidgetPlugin::group() const
{
   return "Display Widgets [Examples]";
}

QIcon SelectDateWidgetPlugin::icon() const
{
     return QIcon();
}

QString SelectDateWidgetPlugin::toolTip() const
{
     return "";
}

QString SelectDateWidgetPlugin::whatsThis() const
{
     return "";
}

bool SelectDateWidgetPlugin::isContainer() const
{
     return false;
}

QString SelectDateWidgetPlugin::domXml() const
{
     return "<widget class=\"SelectDateWidget\" name=\"Select Date\">\n"
            " <property name=\"geometry\">\n"
            "  <rect>\n"
            "   <x>0</x>\n"
            "   <y>0</y>\n"
            "   <width>125</width>\n"
                    "   <height>24</height>\n"
                "  </rect>\n"
                " </property>\n"
                " <property name=\"toolTip\" >\n"
                "  <string>The current time</string>\n"
                " </property>\n"
                " <property name=\"whatsThis\" >\n"
                "  <string>The analog clock widget displays "
                "the current time.</string>\n"
                " </property>\n"
                "</widget>\n";
}

QString SelectDateWidgetPlugin::includeFile() const
{
    return "selectdatewidget.h";
}

Q_EXPORT_PLUGIN2(customwidgetplugin, SelectDateWidgetPlugin)



selectdatewidget.h
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
#ifndef SELECTDATEWIDGET_H
#define SELECTDATEWIDGET_H

#include <QWidget>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <Qt>
#include <QtDesigner/QDesignerExportWidget>

class QDESIGNER_WIDGET_EXPORT SelectDateWidget : public QWidget
{
        public:
                SelectDateWidget(QWidget *parent=0);
        private:
                QHBoxLayout hboxLayout;
                QLabel *label;
                QLineEdit *lineEdit;

};

#endif



selectdatewidget.cpp
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
#include "selectdatewidget.h"


SelectDateWidget::SelectDateWidget(QWidget *parent)
        : QWidget(parent)
{
        QHBoxLayout *hboxLayout = new QHBoxLayout(this);
        hboxLayout->setSpacing(0);
        hboxLayout->setContentsMargins(0,0,0,0);
        lineEdit = new QLineEdit(parent);
    lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(lineEdit->sizePolicy().hasHeightForWidth());
    lineEdit->setSizePolicy(sizePolicy);

        hboxLayout->addWidget(lineEdit);

        label = new QLabel(parent);
        label->setObjectName(QString::fromUtf8("label"));
        label->setMinimumSize(QSize(24, 24));
        label->setPixmap(QPixmap());
        hboxLayout->addWidget(label);
}



selectdatewidget.pro
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
TEMPLATE    = lib
CONFIG      += designer plugin debug_and_release
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target

# Input
HEADERS += selectdatewidget.h \
                   customwidgetplugin.h
SOURCES += selectdatewidget.cpp \
                   customwidgetplugin.cpp

This post has been edited 6 time(s), it was last edited by leoclog: 11.04.2008 21:25.

10.04.2008 19:40 leoclog is offline Send an Email to leoclog Search for Posts by leoclog Add leoclog to your Buddy List
Messenger Messenger is a male
Expert


Registration Date: 20.04.2007
Posts: 298
Location: Lt

Level: 26 [?]
Experience: 116,867
Next Level: 125,609

8,742 points of experience needed for next level

RE: Why does my plugin widget not show? Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

I think
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
class QDESIGNER_WIDGET_EXPORT SelectDateWidget : public QWidget
{
    Q_OBJECT // without this meta object system will function wrong.
        public:
                SelectDateWidget(QWidget *parent=0);
        private:
                QHBoxLayout hboxLayout;
                QLabel *label;
                QLineEdit *lineEdit;

};


__________________
Fighting fire with fire.
11.04.2008 07:54 Messenger is offline Search for Posts by Messenger Add Messenger to your Buddy List
leoclog
Assistant


Registration Date: 10.04.2008
Posts: 5

Level: 6 [?]
Experience: 181
Next Level: 282

101 points of experience needed for next level

Thread Starter Thread Started by leoclog
Daumen hoch! RE: Why does my plugin widget not show? Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

Hi Messenger,

Thank you very much. It has done the trick. I've been staring at the code for ages and just overlooked the macro.

Cheers,

Leo
11.04.2008 21:23 leoclog is offline Send an Email to leoclog Search for Posts by leoclog Add leoclog to your Buddy List
Tree Structure | Board Structure
Jump to:
Post New Thread Post Reply
Qt Forum - programming with C++ and Qt » QtForum.org » Qt » Qt Designer » Why does my plugin widget not show?

views today: 9.440 | views yesterday: 17.520 | total views: 10.242.809


Klebekork Shop - Linux Shop - Kontaktanzeigen - Linux Forum -  SMS Gewinnspiel -  Hotels -  Stadtpläne -  Branchenbuch & Stadtplan

Branchenbuch Österreich - Branchenbuch Niederlande - Portugal Branchenverzeichnis - Spanien Branchenverzeichnis 
Telefonbuch - Branchenbuch Frankreich