PDA

View Full Version : Need help making plugin



vieraci
22nd September 2007, 06:41
I'm trying to build a plugin, but make produces an error which I don't know what to do...

Following the directions from the book "C++ GUI Programming with Qt4"
I have 2 parallel directories: clientNotebook which has the .ui part (compiled without errors) and clientNotebookPlugin dir.

Problem is when I try to make the plugin, i get the following error:

clientNotebookPlugin.cpp: In member function ‘virtual QWidget* ClientNotebookPlugin::createWidget(QWidget*)â€⠄¢:
clientNotebookPlugin.cpp:48: error: expected type-specifier before ‘ClientNotebook’
clientNotebookPlugin.cpp:48: error: cannot convert ‘int*’ to ‘QWidget*’ in return
clientNotebookPlugin.cpp:48: error: expected ‘;’ before ‘ClientNotebook’
clientNotebookPlugin.cpp:48: error: ‘ClientNotebook’ was not declared in this scope
make: *** [clientNotebookPlugin.o] Error 1

This is (I think is relevant) source code in the plugin directory...

// The plugin .pro file:

TEMPLATE = lib
CONFIG += designer plugin release

HEADERS += ../clientNotebook/clientNotebook.h\
clientNotebookPlugin.h
SOURCES += ../clientNotebook/clientNotebook.cpp\
clientNotebookPlugin.cpp

DESTDIR = /usr/local/Qt4.3/plugins/designer
// eof

// The plugin cpp file:

#include <QtPlugin>

#include "./clientNotebookPlugin.h"

ClientNotebookPlugin::ClientNotebookPlugin(QObject *parent)
: QObject (parent)
{
}

.... name() includeFile() group() etc...

// This is the problem function...

QWidget *ClientNotebookPlugin::createWidget(QWidget *parent)
{
return new ClientNotebook(parent);
}

Q_EXPORT_PLUGIN2(clientNotebookPlugin, ClientNotebookPlugin)

// eof

// plugin.h file:
#ifndef CLIENTNOTEBOOKPLUGIN_H
#define CLIENTNOTEBOOKPLUGIN_H

#include <QDesignerCustomWidgetInterface>


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

public:
ClientNotebookPlugin(QObject *parent = 0);
QString name() const;
QString includeFile() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QWidget *createWidget(QWidget *parent);
};

#endif

jpn
22nd September 2007, 07:05
Try including "clientNotebook.h" in clientNotebookPlugin.cpp.

vieraci
23rd September 2007, 11:57
Now that I've inserted the plugin into a form, it doesn't compile:

In file included from mainmenu.h:19,
from main.cpp:16:
ui_mainmenu.h:36:34: error: clientNotebookPlugin.h: No such file or directory
In file included from mainmenu.h:20,
from main.cpp:16:
clientNotebookPlugin/clientNotebookPlugin.h:4:42: error: QDesignerCustomWidgetInterface: No such file or directory

Why is ui_mainmenu.h not resolving ?
Doesn't Qt look in the plugin dir for it ?
Do I need to set something in .pro file ?

jpn
23rd September 2007, 12:37
ui_mainmenu.h:36:34: error: clientNotebookPlugin.h: No such file or directory

Does ClientNotebookPlugin::includeFile() return "clientNotebookPlugin.h"? If so, make it return "clientNotebook.h" (or whatever is the correct file name).



clientNotebookPlugin/clientNotebookPlugin.h:4:42: error: QDesignerCustomWidgetInterface: No such file or directory

Try adding "CONFIG += designer" to the .pro file (and re-generating the vs project).

vieraci
23rd September 2007, 14:01
Does ClientNotebookPlugin::includeFile() return "clientNotebookPlugin.h"? If so, make it return "clientNotebook.h" (or whatever is the correct file name).

YES ! ok, fixed, rebuilt plugin, cleaned project, rebuilt...but now:

In file included from mainmenu.h:19,
from main.cpp:8:
ui_mainmenu.h:36:28: error: clientNotebook.h: No such file or directory


Try adding "CONFIG += designer" to the .pro file (and re-generating the vs project).

No difference.

jpn
23rd September 2007, 15:20
The plugin is just for using clientNotebook in designer. You still need to include clientNotebook to you project.

vieraci
24th September 2007, 12:05
Thanks again, that should have been obvious to me.
Now I'm receiving yet ANOTHER undefined reference...

mainmenu.o: In function `Ui_MainMenu::setupUi(QMainWindow*)':
mainmenu.cpp:(.text._ZN11Ui_MainMenu7setupUiEP11QM ainWindow[Ui_MainMenu::setupUi(QMainWindow*)]+0x2094): undefined reference to `ClientNotebook::ClientNotebook(QWidget*)'
mainmenu.cpp:(.text._ZN11Ui_MainMenu7setupUiEP11QM ainWindow[Ui_MainMenu::setupUi(QMainWindow*)]+0x296d): undefined reference to `ClientNotebook::ClientNotebook(QWidget*)'
collect2: ld returned 1 exit status

Sorry, I've spent hours over this but I can't work out why. I wish I had more knowledge :-(

I tried placing the cpp and .o files in the same directory but it didn''t help.

jpn
24th September 2007, 12:14
Did you add clientNotebook.h and clientNotebook.cpp to the application's .pro file?

vieraci
24th September 2007, 12:33
ok, added them, new error message:

clientNotebook.o: In function `ClientNotebook::ClientNotebook(QWidget*)':
clientNotebook.cpp:(.text+0x31): undefined reference to `vtable for ClientNotebook'
clientNotebook.cpp:(.text+0x38): undefined reference to `vtable for ClientNotebook'
clientNotebook.o: In function `ClientNotebook::ClientNotebook(QWidget*)':
clientNotebook.cpp:(.text+0xb1): undefined reference to `vtable for ClientNotebook'
clientNotebook.cpp:(.text+0xb8): undefined reference to `vtable for ClientNotebook'

Am using 2
clientNotebook widgets in mainMenu, hence error message twice.

jpn
24th September 2007, 13:02
Did you remember to re-run qmake or did you just add the file through an IDE or so?

vieraci
24th September 2007, 13:20
That was it !!
I mistakenly put the header file listed in SOURCES instead of HEADERS...

SOURCES = main.cpp \
mainmenu.cpp \
clientNotebook/clientNotebook.cpp \
clientNotebook/clientNotebook.h

Thank you very much. :-)