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

以下是重现问题的步骤 .

在Mac上的Qt 5.0.1 .

  • 打开QTCreator . 基于QMainWindow类创建新项目 .

  • 将opengl添加到.pro文件:

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

#include <QGLWidget>

class GLWidget : public QGLWidget 
{
    Q_OBJECT
public:
    GLWidget() {};
};
  • 在Designer中做一些事情:

  • 在主窗口上放置三个垂直布局 .

  • 在垂直分割器中组织它们 .

  • 将CentralWidget布局设置为水平 .
    QT Creator screenshot

  • 将mainWowow构造函数放在mainwindow.cpp代码中,该代码将GLWidget添加到窗口:

ui->verticalLayout_2->addWidget(new GLWidget);
  • 跑 . 好!
    App screenshot

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

  • 再次跑......崩溃!

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>

这是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;
    }

How can I workaround this?