[Interest] Build a Qt3D scene in C++ and use it in a QtQuick one

Gil H qt at tastytech.ca
Thu Sep 6 20:49:58 CEST 2018


If all you need is to have Scene3D as part of your QML but the entire entity hierarchy come from C++, then you should be able to do that just by creating the C++ entities and passing the root to the entity property of the Scene3D item.  You can set properties on QML items from C++ and you can read values from C++ inside your QML.  Many 3D entities are easier to describe in QML (e.g. the framegraph itself and custom materials), and I'm not sure of the implications of mixing entities created in C++ and QML in terms of object ownership, threading, lifecycle, etc.  I've slogged through so many crashes and freezes when trying to adopt Qt3D in an "unconventional" use case that I can't remember each issue I've faced along the way.  But hopefully things will go more smoothly for you.  Highly recommend basing any work off the very latest Qt3D code if you can (5.11.2 branch)

Cheers,

Gil


On 9/6/18, 2:36 PM, "interest-bounces+qt=tastytech.ca at qt-project.org on behalf of dns.botond at gmail.com" <interest-bounces+qt=tastytech.ca at qt-project.org on behalf of dns.botond at gmail.com> wrote:

    Hi,
    
    According to the documentation [1] there are two ways to use Qt3D:
    * From C++.
    * From QML.
    
    There is also a bridge class (Qt3DScene2D) which allows rendering a
    QtQuick2 content into a Qt3D scene and another one (QtQuick.Scene3D)
    which allows for the opposite, rendering a Qt3D scene into a QtQuick
    one, however this latter only allows working with the Qt3D QML types. 
    What I would like to do is to generate the scene from C++ and use it in
    a QtQuick2 GUI. Kinda like how inheriting from QQuickItem allows one to
    do the drawing in C++ and seamlessly integrate the resulting item into
    a QML scene.
    Looking at the sources [2] this should be easily achievable, all we'd
    need is a slightly modified `Scene3DItem` class which allows the
    inheriting class to set up the entity tree and other aspects of the
    scene and not allowing these to be meddled with from QML (basically
    stripping all existing properties and invokables and requiring them to
    be set by C++ code).
    
    Are there any plans to allow for something like this? Or is there
    already a way to do this that I'm not aware of?
    
    Regards,
    Botond
    
    [1] https://doc.qt.io/qt-5/qt3d-index.html
    [2] 
    https://code.qt.io/cgit/qt/qt3d.git/tree/src/quick3d/imports/scene3d
    
    _______________________________________________
    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/20180906/0f494a03/attachment.html>


More information about the Interest mailing list