QGLWidget is a widget and it takes am QWidget*
as a parent, so it's a good idea to use that kind of parent for your widget class too: explicit Viewport(QWidget *parent = 0); //don't forget to modify the .cpp too
Subclassing QGLWidget using Qt Creator error
-
04-06-2022 - |
Question
I'm trying to make a simple subclass of QGLWidget
using Qt creator, I generated the .h and .cpp file using the Qt Creator wizard which generated the following code:
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
I added QT += opengl
to the .pro file which got rid of most of the errors but I'm left with two that I don't understand:
/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)'
Ive not changed anything, just trying to compile what Qt gave me, any ideas?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow