[Qt-qml] Plugin example [was: Re: A simple, complete example of QML onvoking C++?]

Matthias Ettrich matthias.ettrich at nokia.com
Wed Apr 14 16:08:12 CEST 2010


Hi,

attached is a small example button.zip which demonstrates how to create a C++ 
plugin which can be used fom qml. The plugin implements a native type called 
NativeBackend which implements a C++ function called nativeFunction().

An instance of NativeBackend is instantiated declaratively in Button.qml.

Unzip, cd to button, call qmake, make and run it with qml Button.qml. Clicking 
on the text label will change the text to the return value of the native 
function.

The file qmldir has to live in the same directory as Button.qml. The engine 
parses it automatically when loading Button.qml. The files contains the single 
line "plugin nativebackend lib" which makes the engine expect a plugin binary 
in the lib subdirectory.

If you run qml with QML_IMPORT_TRACE=1 you will also get debug output from the 
import loading mechanism:

~/tmp/button$ QML_IMPORT_TRACE=1 qml Button.qml 
QDeclarativeEngine::addImportPath "/home/ettrich/dev/qt-qml/bin" 
QDeclarativeEngine::addToImport 0xeffa70 "." -1.-1 File as ""
QDeclarativeEngine::add: loaded "/home/ettrich/tmp/button/qmldir" 
QDeclarativeEngine::importPlugin ".home.ettrich.tmp.button" from 
"/home/ettrich/tmp/button/lib/libnativebackend.so" 
QDeclarativeEngine::addToImport 0xeffa70 "Qt" 4.6 Library as ""
QDeclarativeEngine::resolveType "Rectangle" = "QDeclarativeRectangle" 
QDeclarativeEngine::resolveType "NativeBackend" = "NativeBackend" 
QDeclarativeEngine::resolveType "Text" = "QDeclarativeText" 
QDeclarativeEngine::resolveType "MouseArea" = "QDeclarativeMouseArea" 
Wall startup time: 7 


Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: button.zip
Type: application/zip
Size: 1767 bytes
Desc: not available
Url : http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100414/f91c011d/attachment.zip 


More information about the Qt-qml mailing list