将QGLWidget放入QTabWidget会导致警告“层次结构不一致......”

时间:2013-07-18 16:08:19

标签: qt opengl

我有一个标签并放置一个从QGLWidget继承的对象。 OpenGL工作正常但不知何故显示警告:

inconsistent hierarchy, parent: QAccessibleInterface(0x28297c8 name="" role=User
Role obj=QStackedWidget(0x2826b80, name = "qt_tabwidget_stackedwidget") "invisib
le" )  child: QAccessibleInterface(0x26f5d18 name="" role=Client childc=1 obj=QW
idget(0x26ec968, name = "tab") "invisible" )

如果我将GL对象放在标签之外,则不会显示任何警告。所以我怀疑QTabWidget和QGLWidget之间有什么问题。顺便说一句,我使用的是Qt 5.0.2和Visual Studio 2010

这是一个简单的UI设计示例和重现问题的代码

enter image description here

GLImageDisplay.h

#ifndef _GLImageDisplay_H_
#define _GLImageDisplay_H_

#include "stdafx.h"

#include <QtOpenGL/QGLWidget>

class GLImageDisplay : public QGLWidget
{
    Q_OBJECT

public:
    GLImageDisplay(QWidget *parent = 0);
protected:
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
};

#endif

GLImageDisplay.cpp

#include "stdafx.h"
#include "GLImageDisplay.h"

#include <GL/glu.h>
#include <GL/glut.h>

GLImageDisplay::GLImageDisplay(QWidget *parent) : QGLWidget (parent) 
{
    setMouseTracking(true);
}

void GLImageDisplay::initializeGL() 
{
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_COLOR_MATERIAL);
    glEnable(GL_BLEND);
    glEnable(GL_POLYGON_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glClearColor(0, 0, 0, 0);
}

void GLImageDisplay::resizeGL(int w, int h) 
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, w, 0, h);
    glLoadIdentity();
}

void GLImageDisplay::paintGL() 
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1,0,0);
    glBegin(GL_POLYGON);
    glVertex2f(100,100);
    glVertex2f(100,300);
    glVertex2f(300,100);
    glEnd();
}

在setupUi函数(生成的代码)中,调用tabWidget-&gt; addTab(tab,QString())后会出现警告;

void setupUi(QMainWindow *QTGLTestClass)
{
    if (QTGLTestClass->objectName().isEmpty())
        QTGLTestClass->setObjectName(QStringLiteral("QTGLTestClass"));
    QTGLTestClass->resize(600, 400);
    centralWidget = new QWidget(QTGLTestClass);
    centralWidget->setObjectName(QStringLiteral("centralWidget"));
    gridLayout_2 = new QGridLayout(centralWidget);
    gridLayout_2->setSpacing(6);
    gridLayout_2->setContentsMargins(11, 11, 11, 11);
    gridLayout_2->setObjectName(QStringLiteral("gridLayout_2"));
    tabWidget = new QTabWidget(centralWidget);
    tabWidget->setObjectName(QStringLiteral("tabWidget"));
    tab = new QWidget();
    tab->setObjectName(QStringLiteral("tab"));
    gridLayout = new QGridLayout(tab);
    gridLayout->setSpacing(6);
    gridLayout->setContentsMargins(11, 11, 11, 11);
    gridLayout->setObjectName(QStringLiteral("gridLayout"));
    widget = new GLImageDisplay(tab);
    widget->setObjectName(QStringLiteral("widget"));

    gridLayout->addWidget(widget, 0, 0, 1, 1);

    tabWidget->addTab(tab, QString()); // WARNING APPEARS /////

    gridLayout_2->addWidget(tabWidget, 0, 0, 1, 1);

    QTGLTestClass->setCentralWidget(centralWidget);

    retranslateUi(QTGLTestClass);

    tabWidget->setCurrentIndex(0);


    QMetaObject::connectSlotsByName(QTGLTestClass);
} // setupUi

1 个答案:

答案 0 :(得分:1)

解决。我使用较新版本Qt 5.1.0并且警告消息消失