Creating a C++ plugin for QML applications

It's not too difficult to write a plugin for Qt/C++ applications, whereas it's somewhat more complex to create a plugin for the QML applications. The idea is the same, and here we will use a very basic example to demonstrate this topic. Basically, this application will encode the text input as Base64 and display it. The Base64 encoding part is implemented in the C++ plugin.

This time, we're going to create the plugin project first, and then complete the QML part. Creating a plugin project for a QML application shares the same procedure. Navigate to Libraries | C++ Library, and then select Qt Plugin with the name as Base64Plugin. Its project file, Base64Plugin.pro, is pasted here:

QT += core qml TARGET = ...

Get Qt 5 Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.