"`"
QSurfaceFormat surfaceFormat;
surfaceFormat.setMajorVersion(4);
surfaceFormat.setMinorVersion(3);
QOpenGLContext openGLContext;
openGLContext.setFormat(surfaceFormat);
openGLContext.create();
QOffscreenSurface surface;
surface.setFormat(surfaceFormat);
surface.create();
openGLContext.makeCurrent(&surface);
QOpenGLFunctions *f = openGLContext.currentContext()->functions();
f->initializeOpenGLFunctions();
f->glFlush();
QSize vpSize = QSize(m_ScreenWidth, m_ScreenHeight);
qDebug("Hi");
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
m_fbo = new QOpenGLFramebufferObject (vpSize, fboFormat);
fboFormat.setTextureTarget(GL_TEXTURE_2D);
RenderAllOPenGLWidgets(); // reendering all widgets based on timestamp.
this->update();
QCoreApplication::processEvents();
QThread::usleep(1000);
m_fbo->release();
QString ImageName = QString::number(FBOCaptureTime) + QString(".png");;
QImage fb = m_fbo->toImage().convertToFormat(QImage::Format_RGB32);
fb.save(ImageName, "PNG");
"`"