You Are Here:

Community: Wiki

This page was last modified on 3 September 2009, at 07:38.

CS001391 - Implementing the Qt plug-in interface

From Forum Nokia Wiki


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

Overview

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.


Important

  • When using Qt for S60 libraries from the (qt_libs_armv5_udeb.sisx) on a device, be sure to build both the plug-in and the loading application in DEBUG(UDEB) mode. This is because Qt uses a build key for each plug-in to ensure that only compatible plug-ins are loaded, and the build mode [debug|release] is part of that build key.
  • In Symbian we have to define the EPOCALLOWDLLDATA variable as true for the plug-ins (library) because Qt macros have initialised global data; see plug-in project files for this.


Preconditions


Project .pro file

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


Header (yourplugin.h)

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);
};


Source (yourplugin.cpp)

#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);


See also


Postconditions

The Qt plug-in interface is implemented.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fCS001424E5fE2dE5fUsingE5ftheE5fE44E45PE4cOYME45NTE5fkeywordE5finE5faE5fE51tE5fpackageE5ffileX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZE71tQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxE71tX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ