C++: Plugins the QT way

Posted by : MOnsDaR | Freitag, 7. Mai 2010 | Published in

Compared to modern languages like C# or Java, C++ lacks in support of dynamically loading code at runtime. It is not easy to implement a portable plugin-framework, but it is possible. Luckily there are frameworks available which make such a functionality possible.

Nokias QT-Framework is one of the most active and best maintained frameworks for C++. Besides the famous GUI-functionality are some neat features like reimplementations of the std-features Lists, Strings, Maps etc. It also has a plugin-framework integrated. For testing purposes, I wrote the MediaMasher plugin-architecture in C++ with QT-Plugins:

SourceFactory

(click on image for resize)

The finished project is uploaded to a git-repository and could be downloaded HERE.

It includes a library which adopts the above UML-architecture. Additionally a binary using the lib with a hardcoded sample-source is included. The path points to a systemsound in Ubuntu 10.04. It could be easily changed in /test/TestMain/main.cpp

For building the project CMake is needed. It was another goal for me to demonstrate how QT and QPlugin could be included in such a build-environment.

Unfortunately there is not much documentation about QPluginLoader and the related mechanisms. Besides an official Plug and Paint example directly in the QT-documententation is just the class reference. There isn’t much info in blogs or by projects using this framework.

Finally I’ll show the POCO-Framework as an alternative to the QT-framework. The ClassLoader-component could be interesting for commercial projects which could not effort a QT developer licence (commercial licences start at 3000€ for QT)

Just ask if there are any questions about the example-code or if I should give some deeper explanation.

(0) Comments

Leave a Response