Qt World Summit: Submit your Presentation

Integration fo Qt3D C++ back-end with QML front-end?

  • Hi,
    I have a full C++ application encapsulating a class derived form Qt3DWindow. This class makes a lot of stuff. Now I have to integrate this class in an application that is written with QML. So, I have a full front-end in QML containing one item for my view/window. The problem is that I do not arrive to make the migration.

    I tried to extract the root entity, add it a camera and a ForwardRenderer, as found in a QML example. But nothing is displayed. In fact even the "clear" operation is not performed. I have seen that the renderer as no surface. So I explicitely set the main window as surface. No change. I tried to put my entity in a Scene3D. No change. I tried to encapsulate all my stuff in a QWidget. But QML does not accept QWidget, according to what I found on Internet.

    So, I am a little bit desperate. If someone has the solution.

  • OK,
    Finally we found the solution. The tip is to create a Scene3D in the qml file. And to create the camera and ForwaqrdRenderer in the QML too (and not in the C++).

        Scene3D {
            id: scene3D
            anchors.fill: parent
            anchors.margins: 10
            focus: true
            Root3DEntity {
                id : root3DEntity
                renderSettings : RenderSettings {
                    id : renderSettings
                    pickingSettings.pickMethod : pickingSettings.PrimitivePicking
                    activeFrameGraph: ForwardRenderer {
                        id: renderer
                        clearColor: "#4d4d4f"
                        camera: Camera {
                            id: camera
                            projectionType: CameraLens.PerspectiveProjection
                            fieldOfView: 45
                            nearPlane: 0.1
                            farPlane: 1000.0
                            position: Qt.vector3d(0.0, 0.0, 2.0)
                            upVector: Qt.vector3d(0.0, 1.0, 0.0)
                            viewCenter: Qt.vector3d(0.0, 0.0, 0.0)