Qt GLWidget + Tree =崩溃

时间:2013-03-14 10:32:12

标签: qt crash qtreeview qglwidget

我是Qt新手,我正在尝试使用QGLWidget和其他一些UI控件创建Qt应用。 它在启动后的短时间内崩溃。

以下是重现问题的步骤。

Mac上的Qt 5.0.1。

  1. 打开QTCreator。基于QMainWindow类创建新项目。
  2. 将opengl添加到.pro文件中:

    QT       += core gui opengl
    
  3. 创建从QGLWidget继承的简单GLWidget类(它什么都不做)

    #pragma once
    
    #include <QGLWidget>
    
    class GLWidget : public QGLWidget 
    {
        Q_OBJECT
    public:
        GLWidget() {};
    };
    
  4. 在Designer中做一些事情:

    • 在主窗口上放置三个垂直布局。
    • 在垂直分割器中组织它们。
    • 将CentralWidget布局设置为水平。 QT Creator screenshot
    • 将mainWowow构造函数放在mainwindow.cpp代码中,该代码将GLWidget添加到窗口中:

      ui->verticalLayout_2->addWidget(new GLWidget);
      
  5. 运行。好! App screenshot

  6. 将QTreeView小部件拖放到设计器的左侧布局中。

  7. 再次跑步...... CRASH!

    0   __pthread_kill          0x7fff83e5d212  
    1   pthread_kill            0x7fff8b77caf4  
    2   abort           0x7fff8b7c0dce  
    3   qt_message_fatal    qlogging.cpp    868 0x101711a88 
    4   QMessageLogger::fatal   qlogging.cpp    356 0x1017122ae 
    5   qt_assert_x qglobal.cpp 1959    0x10170ba5a 
    6   QWidget::mapTo  qwidget.cpp 3866    0x10019dfb8 
    7   QFocusFramePrivate::updateSize  qfocusframe.cpp 95  0x1003b5785 
    8   QFocusFrame::eventFilter    qfocusframe.cpp 282 0x1003b6173 
    9   QCoreApplicationPrivate::sendThroughObjectEventFilters  qcoreapplication.cpp    863 0x10198103c 
    10  QApplicationPrivate::notify_helper  qapplication.cpp    3390    0x10015affb 
    11  QApplication::notify    qapplication.cpp    3359    0x10015fb49 
    12  QCoreApplication::notifyInternal    qcoreapplication.cpp    767 0x101980baf 
    13  QCoreApplication::sendSpontaneousEvent  qcoreapplication.h  206 0x10016329f 
    14  QWidgetWindow::handleResizeEvent    qwidgetwindow.cpp   448 0x1001e1ef5 
    15  QWidgetWindow::event    qwidgetwindow.cpp   160 0x1001e0e18 
    16  QApplicationPrivate::notify_helper  qapplication.cpp    3394    0x10015b025 
    17  QApplication::notify    qapplication.cpp    2825    0x10015cb3f 
    18  QCoreApplication::notifyInternal    qcoreapplication.cpp    767 0x101980baf 
    19  QCoreApplication::sendSpontaneousEvent  qcoreapplication.h  206 0x100dfc6ff 
    20  QGuiApplicationPrivate::processExposeEvent  qguiapplication.cpp 2169    0x100df8870 
    ... <More>              
    
  8. 这是QWidget :: mapTo函数中的断言:

        QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const
        {
            QPoint p = pos;
            if (parent) {
                const QWidget * w = this;
                while (w != parent) {
                    Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPoint &pos)",
                       "parent must be in parent hierarchy");
                    p = w->mapToParent(p);
                    w = w->parentWidget();
                }
            }
            return p;
        }
    

    我该如何解决这个问题?

0 个答案:

没有答案