我试图使用Qt创建者创建一个简单的QGLWidget子类,我使用generated向导生成.h和.cpp文件,该向导生成以下代码:
viewport.cpp
#include "viewport.h"
Viewport::Viewport(QObject *parent) :
QGLWidget(parent)
{
}viewport.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给我的东西,有什么想法吗?
发布于 2013-07-24 06:54:12
QGLWidget是一个小部件,它以am QWidget*作为父部件,因此也为您的小部件类使用这种父类是个好主意:explicit Viewport(QWidget *parent = 0); //don't forget to modify the .cpp too
https://stackoverflow.com/questions/17822737
复制相似问题