I have added a QOpenGLWidget object on the main window and this makes the console have a lot of messages such as
QOpenGLContext::makeCurrent() called with non-opengl surface 0x2623b7b7460
QRhiGles2: Failed to make context current. Expect bad things to happen.
QOpenGLContext::makeCurrent() called with non-opengl surface 0x2623dab3450
QRhiGles2: Failed to make context current. Expect bad things to happen.
QOpenGLContext::makeCurrent() called with non-opengl surface 0x2623b7b7460
QRhiGles2: Failed to make context current. Expect bad things to happen.
My .pro file is
QT += core gui openglwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
mainwindow.ui is
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QOpenGLWidget" name="openGLWidget"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>17</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
The mainwindow.h and mainwindow.cpp files are regular, such as QtCreator generated them.
I have tried adding the line QApplication::setAttribute(Qt::AA_ForceRasterWidgets, false); but there are errors both with and without this line:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setAttribute(Qt::AA_ForceRasterWidgets, false);
MainWindow w;
w.show();
return a.exec();
}
Then I deleted the ui and added the QOpenGLWidget manually:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QWidget *centralWidget = new QWidget(this);
this->setCentralWidget( centralWidget );
QGridLayout * gridLayout = new QGridLayout( centralWidget );
QOpenGLWidget* ow = new QOpenGLWidget(this);
gridLayout->addWidget(ow);
}
There were no errors in this case, when QOpenGLWidget was added manually. But it is not comfortable to make a form without Qt Designer.
Can you advise how to get out of the errors about QOpenGLContext and QRhiGles2?
My version of Qt is 6.5, VS2019 compiler, Windows 10.