QT4 Plugins - problems, problems
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 :
Code:
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 :
Code:
#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
The plugin source file :
Code:
#include "plugin.h"
{
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 :
Code:
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.
Re: QT4 Plugins - problems, problems
Quote:
Originally Posted by NormanDunbar
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>.
Quote:
Originally Posted by NormanDunbar
The plugin source file :
You don't seem to be including <QtPlugin> in this file. Q_EXPORT_PLUGIN2 is declared in <QtPlugin>.
Re: QT4 Plugins - problems, problems
Quote:
Originally Posted by dimitri
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 :(
Quote:
Originally Posted by dimitri
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.
Re: QT4 Plugins - problems, problems
Quote:
Originally Posted by NormanDunbar
// 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().
Re: QT4 Plugins - problems, problems
Quote:
Originally Posted by jacek
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.
Re: QT4 Plugins - problems, problems
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.
Re: QT4 Plugins - problems, problems
Afternoon,
Quote:
Originally Posted by fullmetalcoder
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.