Opengl QQuickItem上的Qt矩形未正确渲染

Opengl QQuickItem上的Qt矩形未正确渲染,opengl,qml,qt5,qtopengl,qquickitem,Opengl,Qml,Qt5,Qtopengl,Qquickitem,我在使用QQuickItem的QT5中遇到了一个痛苦的问题。我必须在QML中使用纯openGL绘制一个3D模型,所以我创建了自己的定制QQuickItem。到现在为止,一切都按预期进行:3D模型在QML中显示得非常漂亮 当我想在自定义QQuickItem旁边的同一QML中放置一个简单矩形时,就会出现问题。三维模型不再显示。为什么呢 以下是我的自定义快速项目代码: MQuickItem::MQuickItem(){ isInit = false; connect(

我在使用QQuickItem的QT5中遇到了一个痛苦的问题。我必须在QML中使用纯openGL绘制一个3D模型,所以我创建了自己的定制QQuickItem。到现在为止,一切都按预期进行:3D模型在QML中显示得非常漂亮

当我想在自定义QQuickItem旁边的同一QML中放置一个简单矩形时,就会出现问题。三维模型不再显示。为什么呢

以下是我的自定义快速项目代码:

    MQuickItem::MQuickItem(){
        isInit = false;

    connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
}


    void MQuickItem::handleWindowChanged(QQuickWindow *win){
        w = new SMThickness3DView(/*width(), height()*/);

    if(win){
        connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(initializeMGL()), Qt::DirectConnection);
        connect(win, SIGNAL(beforeRendering()), this, SLOT(paintMGL()), Qt::DirectConnection);
        connect(win, SIGNAL(widthChanged(int)), this, SLOT(resizeMGL()), Qt::DirectConnection);
        connect(win, SIGNAL(heightChanged(int)), this, SLOT(resizeMGL()), Qt::DirectConnection);

        win->setClearBeforeRendering(false);
    }
}

void MQuickItem::initializeMGL(){
    w->initializeGL();
    isInit = true;
}

void MQuickItem::paintMGL(){
    w->paintGL();
//    connect(window()->openglContext(), SIGNAL(aboutToBeDestroyed()), this, SLOT(cleanupMGL()), Qt::DirectConnection);
}

void MQuickItem::resizeMGL(){
    if(isInit){
        w->resizeGL(width(), height());
        w->paintGL();
    }
}

void MQuickItem::cleanupMGL(){
}

void MQuickItem::rotatePerson(bool toLeft){
    if(toLeft)
        w->setYaw(std::min(w->getYaw() + 2., 90.));
    else
        w->setYaw(std::max(w->getYaw() - 2.0, -90.0));
}
这是我的QML,在3D模型上有一个小矩形:

Item {
    anchors.fill: parent
    anchors.centerIn: parent

    MQuickItem {
        id: obj

        property bool mReleased: true
        anchors.fill: parent

        MouseArea{
            id: mArea
            anchors.fill: parent
            drag.target: dummy

            property int initialPressedX;
            property int initialPressedY;

            onPressed: {
                initialPressedX = mArea.mouseX;
                initialPressedY = mArea.mouseY;
            }

            onPositionChanged: {
                var diff = mArea.mouseX - initialPressedX;

                if(Math.abs(diff) > 10){
                    if(diff < 0){
                        obj.rotatePerson(false)
                    }
                    else{
                        obj.rotatePerson(true)
                    }

                    initialPressedX = mArea.mouseX;
                    initialPressedY = mArea.mouseY;
                }
            }

            Rectangle{id: dummy}
        }
    }
    Rectangle{
        id:thisIsTheRectangleThatMakesMyModelDisapear
        width: 50
        height: 50
        color:"red"
    }
}
项目{
锚定。填充:父级
anchors.centerIn:父对象
MQuickItem{
id:obj
属性布尔值已删除:true
锚定。填充:父级
鼠耳{
id:mArea
锚定。填充:父级
drag.target:虚拟
属性int initialPressedX;
属性int initialPressedY;
按下按钮:{
initialPressedX=mArea.mouseX;
initialPressedY=mArea.mouseY;
}
已更改的位置:{
var diff=mArea.mouseX-初始压力x;
如果(数学绝对值(差值)>10){
如果(差异<0){
对象旋转人员(错误)
}
否则{
对象旋转人(真)
}
initialPressedX=mArea.mouseX;
initialPressedY=mArea.mouseY;
}
}
矩形{id:dummy}
}
}
长方形{
id:这是一个使我的模型解体的角度
宽度:50
身高:50
颜色:“红色”
}
}
有谁能给我至少一个关于这个问题的解释,或者一些建议吗