[Interest] [Qt3D] Mixing C++ and QML

Jérôme Godbout jerome at bodycad.com
Thu Oct 19 17:59:39 CEST 2017


You can create your own MyQmlEntity class and expose a method that call it:

class MyQMlEntity : public QEntity
{
  Q_OBJECT
  Q_PROPERTY(VariantList components READ get_components WRITE
set_components NOTIFY componentsChanged)

Q_INVOKABLE void add(QObject* obj) {
addComponent(dynamic_cast<QComponent*>(obj); }
Q_INVOKABLE void remove(QObject* obj)
{ removeComponent(dynamic_cast<QComponent*>(obj)); }
};

you can then read and write data into the underlaying QEntity (this is far
from optimal code, just quick example). You may have to wrap the QComponent
too. you could also make it easier to expose the components list from
QComponentVector to something Qml can handle.

[image: bodycad] <https://www.bodycad.com/>
Jerome Godbout
Software Developer
2035 rue du Haut-Bord, Québec, QC, Canada. G1N 4R7
T:  +1 418 527-1388
E: jerome at bodycad.com
www.bodycad.com

The contents of this email message and any attachments are intended solely
for the addressee(s) and may contain confidential and/or privileged
information and may be legally protected from disclosure. If you are not
the intended recipient of this message or their agent, or if this message
has been addressed to you in error, please immediately alert the sender by
reply email and then delete this message and any attachments. If you are
not the intended recipient, you are hereby notified that any use,
dissemination, copying, or storage of this message or its attachments is
strictly prohibited.

Le contenu de ce message et les pièces jointes sont destinés uniquement
pour le(s) destinataire(s) et peuvent contenir des informations
confidentielles et / ou privilégiées qui peuvent être protégées légalement
contre toute divulgation. Si vous n'êtes pas le destinataire de ce message
ou son agent, ou si ce message vous a été adressé par erreur, s’il vous
plaît avertir immédiatement l'expéditeur par courriel de réponse, puis
supprimer ce message et les pièces jointes. Si vous n'êtes pas le
destinataire prévu, vous êtes par la présente informé que toute
utilisation, diffusion, copie, ou stockage de ce message ou de ses pièces
jointes est strictement interdit.

On Thu, Oct 19, 2017 at 11:40 AM, Xavier Bigand <flamaros.xavier at gmail.com>
wrote:

> The issue is that QEntity doesn't reflect directly the qml type Entity,
> this is the same for many Qt3D classes.
>
> Here is the declaration of QEntity from qentity.h
>
> class QT3DCORESHARED_EXPORT QEntity : public QNode
>
> {
>
>     Q_OBJECT
>
> public:
>
>     explicit QEntity(QNode *parent = nullptr);
>
>     virtual ~QEntity();
>
>
>     QComponentVector components() const;
>
>
>     void addComponent(QComponent *comp);
>
>     void removeComponent(QComponent *comp);
>
>
>     QEntity *parentEntity() const;
>
>
> protected:
>
>     explicit QEntity(QEntityPrivate &dd, QNode *parent = nullptr);
>
>
> private:
>
>     Q_DECLARE_PRIVATE(QEntity)
>
>
>     QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
>
> };
>
>
>
> As you can see the method addComponent is not virtual and exported as Q_PROPERTY, so when creating a derived class of QEntity when instanced in qml it doesn't inherited of Entity properties.
>
>
>
>
> 2017-10-19 15:44 GMT+02:00 Jason H <jhihn at gmx.com>:
>
>> > I am looking for a way to manage an Entity tree in C++ and the Scene
>> configuration in QML. My C++ code manage entities from a root node and I
>> want to move the Frame graph and camera management,... to qml.
>> > I can't figure out how to do that because if create a class that derive
>> from QEntity some properties of Entity aren't declared like "components".
>> >
>> > My goal is to have an object hierarchy made with QEntity in c++ and
>> dynamic views on it made in QML. Scene views should be dockable,...
>>
>>
>> This is well-documented. QEntity inherits from QObject so you are good.
>> I'm not sure what you mean by "like components". Public properties, signals
>> and slots are visible to QML. If not it's a simple matter of wrapping them
>> in a public one.
>>
>> http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
>>
>>
>>
>>
>
>
> --
> Xavier
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171019/a3d74644/attachment.html>


More information about the Interest mailing list