c++qtqmlqt3d

Qt3D: Attempted to set unsupported sample count


(Edit: see comments below: the problem is not related to the NetworkEntity or Network classes.)

I have a Qt3D C++ program that generates a subclass of QEntity which displays just fine inside a C++ Qt3DWindow. When I try to display the exact same QEntity from QML, I get a blank white window and thousands of the following error messages:

Attempted to set unsupported sample count 3342452

Resolve source (7405614) and destination (28) formats do not match

This the C++ code that displays the NetworkEntity just fine:

main.cpp

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    Network net;
    net.startAnimation();

    Qt3DExtras::Qt3DWindow view;
    view.defaultFrameGraph()->setClearColor(QColor(QRgb(0x00000000)));

    // Camera
    Qt3DRender::QCamera *camera = view.camera();
    camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 100.0f);
    camera->setPosition(QVector3D(20.0f, 0.0f, 0.0f));
    camera->setViewCenter(QVector3D(0, 0, 0));

    NetworkEntity *netEntity = new NetworkEntity();
    netEntity->setNet(&net);

    Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(netEntity);
    camController->setLinearSpeed( 3.0f );
    camController->setLookSpeed( 40.0f );
    camController->setCamera(camera);

    view.setRootEntity(netEntity);
    view.show();
    
    return app.exec();
}

This is the QML version of the same which generates the errors:

main.cpp

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    Network net;
    net.startAnimation();

    QQuickView view;

    qmlRegisterType<NetworkEntity>("cv.network", 1, 0, "NetworkEntity");
    view.rootContext()->setContextProperty("_network", &net);
    view.setSource(QUrl("qrc:/overlay.qml"));

    view.show();

    return app.exec();
}

And the QML file that attempts to render the NetworkEntity:

overlay.qml

import QtQuick 2.15
import Qt3D.Core 2.15
import Qt3D.Render 2.15
import Qt3D.Extras 2.15
import Qt3D.Input 2.0
import QtQuick.Scene3D 2.5
import cv.network 1.0

Item {
    Scene3D {
        id: sceneRoot
        anchors.fill: parent
        cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
        focus: true
        enabled: true

        Entity {
            Camera {
                id: camera
                projectionType: CameraLens.PerspectiveProjection
                fieldOfView: 45
                aspectRatio: 16 / 9
                nearPlane: 0.1
                farPlane: 100
                position: Qt.vector3d(20.0, 0, 0)
                upVector: Qt.vector3d(0.0, 0.0, 1.0)
                viewCenter: Qt.vector3d(0.0, 0.0, 0.0)
            }

            OrbitCameraController {
                id: cameraController
                camera: camera
                linearSpeed: 3
                lookSpeed: 40
            }

            components: [
                RenderSettings {
                    activeFrameGraph: ForwardRenderer {
                        clearColor: Qt.rgba(0, 0, 0.1, 1)
                        camera: camera
                        showDebugOverlay: false
                    }
                },
                InputSettings {}
            ]

            NetworkEntity {
                id: myEnt
                net: _network
            }
        }
    }
}

Why does the QML version fail while the C++ version work perfectly? Should I be looking for particular things inside the C++ code that generates the NetworkEntity?

networkentity.h

using namespace Qt3DCore;
using namespace Qt3DExtras;
using namespace Qt3DRender;

class NetworkEntity : public QEntity {
    Q_OBJECT

public:
    NetworkEntity(QEntity *parentEntity = nullptr);
(...)
    Network *net() const;
    void setNet(Network *newNet);

signals:
    void netChanged();

private:
(...)
    Q_PROPERTY(Network *net READ net WRITE setNet NOTIFY netChanged)
};

Q_DECLARE_METATYPE(NetworkEntity);

network.h

#include <QObject>

class Network : public QObject
{
    Q_OBJECT

public:
    explicit Network(QObject *parent = nullptr);
    Network(const Network &network);
    ~Network();

    void startAnimation();
    void stopAnimation();

    QList<Node *> allNodes() const;

    Timebase *getTimebase();
signals:
(...)
private:
(...)
};

Q_DECLARE_METATYPE(Network);

Solution

  • The overlay.qml file did not set any size to the parent Item of the Scene3D. Specifying a size or setting the anchors.fill property resolved the problem.

    This file now works:

    overlay.qml

    import QtQuick 2.15
    import Qt3D.Core 2.15
    import Qt3D.Render 2.15
    import Qt3D.Extras 2.15
    import Qt3D.Input 2.0
    import QtQuick.Scene3D 2.5
    import cv.network 1.0
    
    Item {
        anchors.fill: parent
    
        Scene3D {
            id: sceneRoot
            anchors.fill: parent
            cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
            focus: true
            enabled: true
    
            Entity {
                Camera {
                    id: camera
                    projectionType: CameraLens.PerspectiveProjection
                    fieldOfView: 45
                    aspectRatio: 16 / 9
                    nearPlane: 0.1
                    farPlane: 100
                    position: Qt.vector3d(20.0, 0, 0)
                    upVector: Qt.vector3d(0.0, 0.0, 1.0)
                    viewCenter: Qt.vector3d(0.0, 0.0, 0.0)
                }
    
                OrbitCameraController {
                    id: cameraController
                    camera: camera
                    linearSpeed: 3
                    lookSpeed: 40
                }
    
                components: [
                    RenderSettings {
                        activeFrameGraph: ForwardRenderer {
                            clearColor: Qt.rgba(0, 0, 0.1, 1)
                            camera: camera
                            showDebugOverlay: false
                        }
                    },
                    InputSettings {}
                ]
    
                NetworkEntity {
                    id: myEnt
                    net: _network
                }
            }
        }
    }