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 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")
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")
To copy to clipboard, switch view to plain text mode
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.
};
#endif
#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
To copy to clipboard, switch view to plain text mode
The plugin source file :
#include "plugin.h"
{
return QString("This is some text.");
}
//Q_EXPORT_PLUGIN2(PlugIn_Name, Plugin_class)
Q_EXPORT_PLUGIN2(plugin, TextPlugin)
#include "plugin.h"
QString TextPlugin::GetText()
{
return QString("This is some text.");
}
//Q_EXPORT_PLUGIN2(PlugIn_Name, Plugin_class)
Q_EXPORT_PLUGIN2(plugin, TextPlugin)
To copy to clipboard, switch view to plain text mode
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
}
}
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
}
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks