I want to add an OpenGLWidget to a layout and when my job is done, I want to clean up everything about OpenGLWidget, but When I was open the widget and close with Qt::WA_DeleteOnClose
attribute, the memory is not freeing up completely. Is that normal or am I not know the right usage. I was read the documentation (https://doc.qt.io/qt-5/qopenglwidget.html) and try everything but I can't remove that 40 mb allocation from the memory when creating the widget and closing after them. It is just delete 3-4 mb after close and delete operation. I will use this for another project. (I have to open OpenGLWidget, show some triangles and close the Widget.)
I was try to use makeCurrent() and doneCurrent(), deleteLater() and some more operations but it is not work.
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include<QOpenGLWidget>
QOpenGLWidget *openglWidget;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
openglWidget = new QOpenGLWidget;
openglWidget->setAttribute(Qt::WA_DeleteOnClose);
ui->gridLayout->addWidget(openglWidget);
}
void MainWindow::on_pushButton_2_clicked()
{
ui->gridLayout->removeWidget(openglWidget);
openglWidget->close();
delete openglWidget;
}