Qt3D:尝试设置不支持的样本计数

huangapple go评论74阅读模式
英文:

Qt3D: Attempted to set unsupported sample count

问题

这是您要翻译的部分:

我有一个Qt3D C++程序,它生成`QEntity`的子类,可以在C++的`Qt3DWindow`中正常显示。但是当我尝试从QML中显示完全相同的`QEntity`时,我得到了一个空白的白色窗口,以及数千个以下错误消息:

> 尝试设置不支持的样本计数3342452

> 解析源(7405614)和目标(28)格式不匹配

这是在C++中正常显示`NetworkEntity`的代码:

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();
}

这是相同功能的QML版本,但出现错误的代码:

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();

}


以及尝试渲染`NetworkEntity`的QML文件:

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
            }
        }
    }
}

希望这有助于您理解问题。如果您有任何进一步的问题或需要更多的翻译,请告诉我。

英文:

(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()-&gt;setClearColor(QColor(QRgb(0x00000000)));

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

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

    Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(netEntity);
    camController-&gt;setLinearSpeed( 3.0f );
    camController-&gt;setLookSpeed( 40.0f );
    camController-&gt;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&lt;NetworkEntity&gt;(&quot;cv.network&quot;, 1, 0, &quot;NetworkEntity&quot;);
    view.rootContext()-&gt;setContextProperty(&quot;_network&quot;, &amp;net);
    view.setSource(QUrl(&quot;qrc:/overlay.qml&quot;));

    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 &lt;QObject&gt;

class Network : public QObject
{
    Q_OBJECT

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

    void startAnimation();
    void stopAnimation();

    QList&lt;Node *&gt; allNodes() const;

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

Q_DECLARE_METATYPE(Network);

答案1

得分: 0

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

项目 {
    锚定.fill: 父

    三维场景 {
        id: sceneRoot
        锚定.fill: 父
        相机宽高比模式: 三维场景.自动宽高比
        聚焦: true
        启用: true

        实体 {
            相机 {
                id: camera
                投影类型: CameraLens.透视投影
                视场角: 45
                宽高比: 16 / 9
                近裁剪面: 0.1
                远裁剪面: 100
                位置: Qt.vector3d(20.0, 0, 0)
                上向量: Qt.vector3d(0.0, 0.0, 1.0)
                视图中心: Qt.vector3d(0.0, 0.0, 0.0)
            }

            轨道相机控制器 {
                id: cameraController
                相机: camera
                线性速度: 3
                视图速度: 40
            }

            组件: [
                渲染设置 {
                    activeFrameGraph: 正向渲染器 {
                        清除颜色: Qt.rgba(0, 0, 0.1, 1)
                        相机: camera
                        显示调试叠加层: false
                    }
                },
                输入设置 {}
            ]

            网络实体 {
                id: myEnt
                net: _network
            }
        }
    }
}
英文:

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
            }
        }
    }
}

huangapple
  • 本文由 发表于 2023年5月14日 22:05:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定