I tried to run basic OpenGL example in Qt 6.5 where I only create OpenGL surfaced window. Code is short and clear but I can't see what is missing...
main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setTitle("OpenGL basic");
w.resize(640,480);
w.show();
return a.exec();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QOpenGLWindow>
class MainWindow : public QOpenGLWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event);
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
{
setSurfaceType(QWindow::OpenGLSurface);
}
MainWindow::~MainWindow()
{
}
I hope my question is clear and not so long. Thank you!
.pro file:
QT = core gui
QT += opengl
LIBS += -lopengl32 -lglu32
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenGL
TEMPLATE = app
CONFIG += c++17
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
After searching for few days I found solution on my own.
In Qt 6.5 for OpenGL, they are using QOpenGLWidget.
On this link you can find documentation about QOpenGLWidget: https://doc.qt.io/qt-6/qopenglwidget.html