1

我正在尝试使用 Qt Creator 创建一个简单的子类QGLWidget,我使用 Qt Creator 向导生成了 .h 和 .cpp 文件,该向导生成了以下代码:

视口.cpp

#include "viewport.h"

Viewport::Viewport(QObject *parent) :
    QGLWidget(parent)
{
}

视口.h

#ifndef VIEWPORT_H
#define VIEWPORT_H

#include <QGLWidget>

class Viewport : public QGLWidget
{
    Q_OBJECT
public:
    explicit Viewport(QObject *parent = 0);

signals:

public slots:

};

#endif // VIEWPORT_H

我添加QT += opengl到消除了大部分错误的 .pro 文件中,但留下了两个我不明白的地方:

/projects/tree_gen/qt_project/tree_gen-build-desktop-Qt_4_8_4_in_PATH__System__Debug/../tree_gen/viewport.cpp:4: error: invalid conversion from 'QObject*' to 'QWidget*'

/projects/tree_gen/qt_project/tree_gen-build-desktop-Qt_4_8_4_in_PATH__System__Debug/../tree_gen/viewport.cpp:4: error:   initializing argument 1 of 'QGLWidget::QGLWidget(QWidget*, const QGLWidget*, Qt::WindowFlags)'

我没有改变任何东西,只是试图编译 Qt 给我的东西,有什么想法吗?

4

1 回答 1

0

QGLWidget 是一个小部件,它需要 amQWidget*作为父级,因此最好为您的小部件类使用这种父级:explicit Viewport(QWidget *parent = 0); //don't forget to modify the .cpp too

于 2013-07-24T06:54:12.397 回答