| ID | CS001391 | Creation date | June 10, 2009 |
| Platform | S60 3rd Edition FP1, FP2 S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Qt for S60 | Subcategory | Base/System |
| Keywords (APIs, classes, methods, functions): QPluginLoader, Q_DECLARE_INTERFACE, Q_INTERFACES, Q_EXPORT_PLUGIN2 |
Qt applications can be extended with Qt plug-ins. This code snippet demonstrates how to implement the plug-in on top of the plug-in interface defined in the client application (the interface was described in the code snippet CS001390 - Defining a Qt plug-in interface).
The plug-in has to implement all methods defined in the plug-in interface. Additional methods and member variables can also be implemented. However, note that the client application only sees methods and data that are defined into the common interface exampleplugininterface.h.
The defining of a plug-in interface and plug-in usage are described in additional snippet articles.
Note: In order to use this code, you need to have Qt for S60 installed on your platform.
TEMPLATE = lib
CONFIG += plugin
# Define path where compiler can found your defined interface for the plugins
INCLUDEPATH += ../../
HEADERS = yourplugin.h
SOURCES = yourplugin.cpp
TARGET = $$qtLibraryTarget(yourplugin)
symbian: {
# Load predefined include paths (e.g. QT_PLUGINS_BASE_DIR) to be used in the pro-files
load(data_caging_paths)
# EPOCALLOWDLLDATA have to set true because Qt macros has initialised global data
TARGET.EPOCALLOWDLLDATA=1
# Defines plugin files into Symbian .pkg package
pluginDep.sources = yourplugin.dll
pluginDep.path = $$QT_PLUGINS_BASE_DIR/exampleplugins
DEPLOYMENT += pluginDep
}
target.path += $$[QT_INSTALL_PLUGINS]/exampleplugins
INSTALLS += target
The header for your plug-in that implements your own ExamplePluginInterface plug-in interface.
// Your defined interface for the plugins
#include "exampleplugininterface.h"
class YourPlugin : public ExamplePluginInterface
{
// That is because we use Qt signal/slot feature
// in "void someSlot(QString value)"
Q_OBJECT
// This macro tells Qt which interfaces the class implements
// This is used when implementing plugins
Q_INTERFACES(ExamplePluginInterface)
public: // From ExamplePluginInterface
~LinkPlugin();
QString sayHello();
public slots: // From ExamplePluginInterface
void someSlot(QString value);
};
#include <QtCore/qplugin.h>
#include "yourplugin.h"
YourPlugin::~YourPlugin()
{
}
QString YourPlugin::sayHello()
{
return QString("Hello from YourPlugin: "+data);
}
void YourPlugin::someSlot(QString value)
{
data = value;
}
// This Qt macro exports the plugin class YourPlugin with the
// name "exampleplugins"
// There should be exactly one occurrence of this YourPlugin
// macro in a Qt plugin's source code.
Q_EXPORT_PLUGIN2(exampleplugins, YourPlugin);
The Qt plug-in interface is implemented.
No related wiki articles found