PDA

View Full Version : QT4 Plugins - problems, problems



NormanDunbar
8th May 2006, 13:02
Greetings,

anyone got QT4 plugins to work yet, other than the PlugAndPaint demo supplied with QT4.1.2 ?

I'm using QT 4.1.2, mingw compiler and Windows 2000.

I'm able to get the above demo to compile, but when I try to build my own simple test setup, I continually get this error :

plugin.cpp:10: error: expected constructor, destructor, or type conversion before '(' token
plugin.cpp:10: error: expected `,' or `;' before '(' token
mingw32-make[1]: *** [release\plugin.o] Error 1

For now, everything is in the same folder. I have three files :

The interface header :


class QString;

class PluginInterface {
public:
// Destructor - does nothing.
virtual ~PluginInterface() {}

// Simple interface - returns some text in a QString.
virtual QString GetText() const = 0;
};

Q_DECLARE_INTERFACE(PluginInterface, "dunbar-it.co.uk.test.TextInterface/1.0")


The header file for my plugin :


#ifndef plugin_h
#define plugin_h

#include <QObject>
#include <QString>

#include "interfaces.h"

class TextPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)

public:
// Destructor - does nothing.
~TextPlugin() {}

// Simple interface - returns some text in a QString.
QString GetText();
};

#endif


The plugin source file :


#include "plugin.h"

QString TextPlugin::GetText()
{
return QString("This is some text.");
}

//Q_EXPORT_PLUGIN2(PlugIn_Name, Plugin_class)

Q_EXPORT_PLUGIN2(plugin, TextPlugin)


The project file is named 'plugin.pro' and contains the following :


TEMPLATE = lib
CONFIG += plugin
HEADERS = plugin.h
SOURCES = plugin.cpp
DESTDIR = ../plugins

contains(TEMPLATE,lib) {
CONFIG(debug, debug|release) {
unix:TARGET = $$member(TARGET, 0)_debug
else:TARGET = $$member(TARGET, 0)d
}
}


The error message only appears when I have the Q_EXPORT_PLUGIN2 macro in my cpp file. The error line is indeed that line.

Any hints and tipe from those of you much better than I am at QT and C++ programming will be gratefully received. Thanks.

Cheers,
Norman.

dimitri
8th May 2006, 13:10
For now, everything is in the same folder. I have three files :

The interface header :
You don't seem to be including any Qt header in this file. Q_DECLARE_INTERFACE is declared in <QObject>.


The plugin source file :
You don't seem to be including <QtPlugin> in this file. Q_EXPORT_PLUGIN2 is declared in <QtPlugin>.

NormanDunbar
8th May 2006, 13:30
You don't seem to be including any Qt header in this file. Q_DECLARE_INTERFACE is declared in <QObject>.

That one made no difference :(


You don't seem to be including <QtPlugin> in this file. Q_EXPORT_PLUGIN2 is declared in <QtPlugin>.

But that one made all the difference.

I suppose it was my own fault really, I was following the instructions given in the documentation for QT4.

Much obliged for the prompt and accurate reply, thank you.


Cheers,
Norman.

jacek
8th May 2006, 13:30
// Simple interface - returns some text in a QString.
virtual QString GetText() const = 0;
...
// Simple interface - returns some text in a QString.
QString GetText();
There is a "const" keyword missing after TextPlugin::GetText().

NormanDunbar
8th May 2006, 13:33
There is a "const" keyword missing after TextPlugin::GetText().

Indeed there was, thanks. I've fixed that as well. The real fix, however, was a missing #include <QtPlugin> in the cpp file. AT least, that allowed it to compile, I've yet to write the 'app' that uses the test plugin ... :)

Cheers,
Norman.

fullmetalcoder
9th May 2006, 14:53
That is the hard part indeed. If you need some ideas have a look at the last version of DevQt, it uses a plugin system to customize every aspect of the app.

NormanDunbar
9th May 2006, 15:39
Afternoon,


That is the hard part indeed. If you need some ideas have a look at the last version of DevQt, it uses a plugin system to customize every aspect of the app.

Sppokily enough, I set a compilation of DevQt running this very morning - just to see what it is/does. I shall have to have a quick look now. Thanks for the pointer though.

Cheers,
Norman.