Hello Matthias
Thanks for sharing your example -- this is exactly the kind of sample needed :-)
A few points:
- in the QML file, don't we need to add a line to refer to the shared object,
i.e. something like this: "import NativeBackend"
- I get this runtime error (presumably because of the missing import?)
file:///.../button/Button.qml:6:5: Type NativeBackend unavailable
NativeBackend { id: nativeBackend; }
- during my initial build attempt, there seemed to be an endless loop of
messages saying:
"button.pro has a future date"
This is probably because you are in a later timezone than me?
Anyway, I got around this by re-saving each of the files with my local time
and all was well after that
Kind regards
Peter
-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Matthias Ettrich
Sent: Wednesday, April 14, 2010 7:08 AM
To: [email protected]
Subject: [Qt-qml] Plugin example [was: Re: A simple,complete example of QML
onvoking C++?]
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
---------------------------------------------------------------------------
This email and any files transmitted with it are confidential & proprietary to
Systems and
Software Enterprises, Inc. (dba IMS). This information is intended solely for
the use of
the individual or entity to which it is addressed. Access or transmittal of the
information
contained in this e-mail, in full or in part, to any other organization or
persons is not
authorized.
---------------------------------------------------------------------------
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml