I have find a way to get a QImage of an QWindow:
Make a standard QWindow with is surface and add the following code:
// set the current context OpenGL
// check if an OpenGlContext is created
QOpenGLContext context;
context.setFormat(format());
if (!context.create())
qFatal("Cannot create the requested OpenGL context!");
context.makeCurrent(this);
// init a new framebuffer
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
fboFormat.setMipmap(true);
fboFormat.setSamples(4);
fboFormat.setTextureTarget(GL_TEXTURE_2D);
fboFormat.setInternalTextureFormat(GL_RGB);
resize(this->width(), this->height());
const QRect drawRect(0, 0, this->width(), this->height());
const QSize drawRectSize = drawRect.size();
_fbo = new QOpenGLFramebufferObject(drawRectSize, fboFormat);
_fbo->bind();
...
_fboImage = new QImage(_fbo->toImage(false));
But, this is work only if the window is "visible", when it is set to Hidden the rendering of Qt3D was made (the rendering loop, because the GPU is used and the FPS is divided by 3), but the QOpenGLFramebufferObject was not filled :/
Do you have any idea of how force the filling of the fbo ?
PS: I have found this here : http://stackoverflow.com/questions/17221730/do-offscreen-renderopengl-with-qt5