PDA

View Full Version : Testing a custom Plugin



maluta
1st May 2006, 19:17
I've created a custom plugin and put this on my designer widget box, after I created a new form (widget) for an application to test my plugin...
I just drop my custom plugin in a form widget and wrote the main.cpp file



#include <QApplication>
#include <QDialog>

#include "ui_form.h"

int main(int argc,char *argv[]) {

QApplication app(argc,argv);
QDialog* tela = new QDialog;
Ui::Form ui;
ui.setupUi(tela);
tela->show();
return app.exec();

}


But when I compile the source code, I got the follwing message:

g++ -c -pipe -march=pentium4 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/doc/qt-4.1.1/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
g++ -o teste_plugin_2 main.o -L/usr/lib/qt4 -lQtGui -L/usr/lib/mysql -L/usr/lib/qt4 -L/usr/lib -laudio -lXt -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXcursor -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -ldl -lpthread
main.o: In function `main':
main.cpp:(.text+0x1a7): undefined reference to `MyButtons::MyButtons(QWidget*)'
collect2: ld returned 1 exit status
make: ** [teste_plugin_2] Erro 1

Here is my class definition (because I'm using a plugin I have to files mybuttons.h and mybuttonplugin.h, but I think the problem is on mybutton.h)



#ifndef MYBUTTONS_H
#define MYBUTTONS_H

#include <QPushButton>
#include <QHBoxLayout>
#include <QWidget>
#include <QtDesigner/QDesignerExportWidget>

class QDESIGNER_WIDGET_EXPORT MyButtons : public QWidget {

Q_OBJECT
public:
MyButtons(QWidget *parent=0);
protected:
void setB1Text(const QString&);
void setB2Text(const QString&);
const QString getB1Text() const;
const QString getB2Text() const;
signals:
void B1Clicked();
void B2Clicked();
private:
QPushButton* B1;
QPushButton* B2;
QHBoxLayout* layout;
};
#endif


And the constructor implementation



MyButtons::MyButtons(QWidget* parent) : QWidget(parent) {

B1 = new QPushButton();
B2 = new QPushButton();
layout = new QHBoxLayout(this);

layout->addWidget(B1);
layout->addWidget(B2);

connect (B1, SIGNAL(clicked()), this, SIGNAL(B1Clicked()));
connect (B2, SIGNAL(clicked()), this, SIGNAL(B2Clicked()));
}


I'm using qt 4.1.1 (gcc 3.4.0) on a x86 machine.

jacek
1st May 2006, 19:39
You must link your application with the plugin (or at least the implementation of the MyButtons class).

Royceybaby
31st October 2006, 12:23
Can you provide an example of what is meant by:


You must link your application with the plugin (or at least the implementation of the MyButtons class).

I am having the same problem as Maluta.

Thanks,
Royce

jacek
31st October 2006, 14:13
Can you provide an example of what is meant by [...]
If you use qmake, it should be:
LIBS += -lmybuttonplugin
or

SOURCES += mybutton.cpp
HEADERS += mybutton.h
depending on what you want to achieve.

Royceybaby
31st October 2006, 14:30
I have subclassed QTableWidget and have made a designer plugin called EnhancedTableWidget.

I have successfully compiled the designer plugin and copied the two files

enhancedtablewidget.dll
libenhancedtablewidget.a

to the $QTDIR\plugins\designer directory.

I can create a new form with my new widget on it.

When I try and compile a simple example using Maluta's main.cpp I get the following error:


release\main.o(.text+0x267):main.cpp: undefined reference to `EnhancedTableWidget::EnhancedTableWidget(QWidget* )'


Here is my current .pro file



TEMPLATE = app
QT += sql
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += enhancedtablewidget.h
FORMS += form.ui
SOURCES += main.cpp
LIBS += C:/Devel/Qt/4.2.0/plugins/designer/libenhancedtablewidgetplugin.a

I am using Qt4.2.0 on Windows XP with mingw.

Thanks,
Royce

jacek
31st October 2006, 15:09
I am using Qt4.2.0 on Windows XP with mingw.
Since you use windows, make sure you have proper __declspec directive between "class" and "EnhancedTableWidget".