Re: How to create a plugin
Re: How to create a plugin
Quote:
Writing a plugin involves these steps:
Declare a plugin class that inherits from QObject and from the interfaces that the plugin wants to provide.
Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces.
Export the plugin using the Q_EXPORT_PLUGIN2() macro.
Build the plugin using a suitable .pro file.
OK, what's a suitable .pro file?
Re: How to create a plugin
I figured it out, but when I compile it says that "myplugin.h:1:17: fatal error: QtGui: No such file or directory".
?????????????????????????
Re: How to create a plugin
Here's a pro file from the examples:
Code:
TEMPLATE = lib
CONFIG += plugin static
INCLUDEPATH += ../..
HEADERS = basictoolsplugin.h
SOURCES = basictoolsplugin.cpp
TARGET = $$qtLibraryTarget(pnp_basictools)
DESTDIR = ../../plugandpaint/plugins
# install
target.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaint/plugins
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS basictools.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins/basictools
INSTALLS += target sources
The file is explained at the end of this webpage:
http://doc.qt.nokia.com/4.6/tools-pl...asictools.html
Re: How to create a plugin
Quote:
Originally Posted by
MTK358
I figured it out, but when I compile it says that "myplugin.h:1:17: fatal error: QtGui: No such file or directory".
?????????????????????????
Did you use "INCLUDEPATH +=" (note the +) in your pro file?
Re: How to create a plugin
static? I thought it had to be dynamic!
Re: How to create a plugin
Re: How to create a plugin
Plugins do not have to be dynamic. Usually, plugins are a special kind of library, not used in other programs.
But, if you have the need to base other plugins on a certain base plugin, than you find it much easier when they are shared instead of static. Well, that's what I think.
Forget about the includepath. I thought you might have added such a line in your .pro file. And if you do not add the +, it will overwrite all the include paths resulting in some includes not being found.
But I guess in your case the problem is somewhere else.
Can you post the code you have please?
Re: How to create a plugin
myplugin.h
Code:
#include <QLabel>
#include "/home/michael/Projects/QPanel/qpanelappletinterface.h"
class ClockPlugin
: public QObject,
public QPanelAppletInterface
{
Q_OBJECT
Q_INTERFACES(QPanelAppletInterface)
public:
MyPlugin();
void showPreferencesDialog();
private:
};
myplugin.cpp
Code:
#include "myplugin.h"
MyPlugin::MyPlugin()
{
label
= new QLabel("Time goes here");
}
{
return label;
}
void MyPlugin::showPreferencesDialog()
{
// no preferences
}
myplugin.pro
Code:
######################################################################
# Automatically generated by qmake (2.01a) Fri Aug 27 08:29:32 2010
######################################################################
TEMPLATE = lib
CONFIG = plugin
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += myplugin.h
SOURCES += myplugin.cpp
Re: How to create a plugin
I'm not sure about the QtGui error at the moment.
Check the source code, your class is called ClockPlugin while everywhere else it is called MyPlugin.
You also need to set a target.
And you need to call that target in the Q_EXPORT_PLUGIN2 macro. Otherwise you're not exporting symbols and the plugin will not be able to be loaded.
Example:
myplugin.pro:
Code:
TARGET = $$qtLibraryTarget(mysuperplugin)
myplugin.cpp: (at the very end of the file)
Code:
Q_EXPORT_PLUGIN2(mysuperplugin, MyPlugin)
Re: How to create a plugin
Re: How to create a plugin
It's the library name of the plugin. You can call it whatever you want.
Re: How to create a plugin
OK, but what about the fact that QtGui is not found?
Re: How to create a plugin
Ohh yes, now I see it.
Add QT += gui to your pro file.
Edit: On the other hand, this should be default, at least for the app template.
Re: How to create a plugin
Re: How to create a plugin
This is weird. I don't see the problem. QMake should find it automatically.
Re: How to create a plugin
Code:
$ ls
Makefile myplugin.cpp myplugin.h myplugin.pro
$ cat myplugin.pro
######################################################################
# Automatically generated by qmake (2.01a) Fri Aug 27 08:29:32 2010
######################################################################
QT += gui
TEMPLATE = lib
CONFIG = plugin
TARGET = $$qtLibraryTarget(myplugin)
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += myplugin.h
SOURCES += myplugin.cpp
$ qmake
$ make
g++ -c -m64 -pipe -march=x86-64 -mtune=generic -O2 -pipe -fPIC -I/usr/share/qt/mkspecs/linux-g++-64 -I. -I. -o myplugin.o myplugin.cpp
In file included from myplugin.cpp:1:0:
myplugin.h:1:17: fatal error: QtGui: No such file or directory
compilation terminated.
make: *** [myplugin.o] Error 1
Re: How to create a plugin
As you can see in the following line:
Code:
g++ -c -m64 -pipe -march=x86-64 -mtune=generic -O2 -pipe -fPIC -I/usr/share/qt/mkspecs/linux-g++-64 -I. -I. -o myplugin.o myplugin.cpp
The following include paths are at least missing:
Code:
-I/usr/include/.../QtCore -I/usr/include/.../QtGui
These are pseudo paths, I don't know where they are on your system.
This is mighty strange as, like I said, when QT += gui and QT += core (which are default, you don't generally have to add those manually to the .pro file) are added to your .pro file, the include paths should be set by qmake.
One thing I can think of is to manually delete the Makefile, and try qmake and make again. But I guess this won't solve it either.
Edit: try this too:
Note the +
When you do not add the +, you erase all the configs
Re: How to create a plugin
Another error:
$ make
/usr/bin/qmake -unix -o Makefile myplugin.pro
g++ -c -m64 -pipe -march=x86-64 -mtune=generic -O2 -pipe -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_PLUGIN -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++-64 -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -o myplugin.o myplugin.cpp
myplugin.cpp: In function ‘QObject* qt_plugin_instance()’:
myplugin.cpp:18:1: error: cannot allocate an object of abstract type ‘MyPlugin’
myplugin.h:6:1: note: because the following virtual functions are pure within ‘MyPlugin’:
/home/michael/junk/QPanel/qpanelappletinterface.h:13:18: note: virtual void QPanelAppletInterface::showSettingsDialog()
make: *** [myplugin.o] Error 1
The interface:
Code:
#ifndef QPANELAPPLETINTERFACE_H
#define QPANELAPPLETINTERFACE_H
#include <QtPlugin>
class QPanelAppletInterface
{
public:
virtual ~QPanelAppletInterface() {}
virtual void showSettingsDialog() = 0;
};
Q_DECLARE_INTERFACE(QPanelAppletInterface, "com.trolltech.PlugAndPaint.QPanelAppletInterface/1.0")
#endif // QPANELAPPLETINTERFACE_H