[Qt-interest] Extending applications with plugins (QPluginLoader)

Bastian Bense bastibense at gmail.com
Wed Aug 12 12:10:52 CEST 2009


Hey all,

I work on an application that provides connections to a central
server, and some basic functionality (like chat, messaging, file
transfers, etc.) and I'd like to provide other developers a plugin
API, so they can extend my application's functionality without having
to mess around with the main code base.

Basically a connection to a server is managed by a so called
"SessionController", which glues the logic of the network protocol
stack (a custom QTcpSocket with high-level functions to send messages
to the server), to the user interface.

Plugins should be able to do the following:
  - Provide additional widgets
  - Add QActions to toolbars and similar things
  - Extend the socket in order to provide additional protocol commands.

The challenge is in providing proper access to the host application's objects.

Plugins are implementing an "Interface" from the host application,
which defines which functions have to be implemented in order for the
plugin to provide hooks and extend functionality. Unfortunately this
is more or less a one-way track:

  - it is overly complex to emit singnals from a plugin which the host
application
  - access to the application code structure is tricky

This means that I can just extend my application by providing hooks
for plugin developers, without giving them a way to access, for
instance, the socket object of the application.

Some expected behaviour of a plugin backend would be something like this:
A plugin is installed and provides additional commands for the network
protocol. To properly handle this, the plugin needs to access the
application's socket and call functions and properties.

An idea was: Include the socket header and provide a pointer through
the plugin to the socket object. Unfortunately linking for the plugin
fails, because, obviously, there is no effective code for the socket
in the plugin (as it is provided by the host application).

Is the plugin backend just thought as a quick and easy way to provide,
for instance, additional codecs for a video player or additional file
formats? What are the usual approaches to provide flexible access to
the application from the plugin?

Thanks in advance for any ideas and thoughts.

--
Best regards,
Bastian Bense




More information about the Qt-interest-old mailing list