[Interest] Qt3D/QML How to access a QTransform based property from C++

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Wed Aug 30 11:29:28 CEST 2017


Il 30/08/2017 10:07, Volker Enderlein ha scritto:
> Entity {
>       id: root
> 
>       property Transform frame: Transform {}
>       property Material mat: PhongMaterial { diffuse: Qt.rgba(0.8, 0.8,
> 0.8, 1.0) }
> ...
> 
> }
> 
> Later I try to update the Transform and Material from C++. But I cannot
> set the properties via qmlEntity->setProperty("Transform",
> QVariant(Qt3DCore::QTransform)); because QTransform is not usable as
> metatype.

The type of the property is QTransform*, not QTransform -- pass a 
pointer to your QTransform object to setProperty. (Also, the name of the 
property is "frame", not "Transform".)

IOW:

Qt3DCore::QTransform *t = ...;
entity->setProperty("frame", t);

> How would I do that, or should I use an entirely different approach?

Another approach is exposing the QTransform to the QML engine (for 
instance via engine->setContextProperty("_myTransform", t)), then using 
_myTransform in QML:

Entity {
     components: [ _myTransform, ... ]
}


Hope this helps,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170830/7d337c82/attachment.bin>


More information about the Interest mailing list