I have a Qt 5.2.1 program that uses QOpenGLVertexArrayObjects and creates more than one QGLWidget, each placed inside of a QStackedWidget. Thus, only one QGLWidget is visible at any one time.

The issue is -- if I close the program and the QGLWidget that uses a QOpenGLVertexArrayObject ISN'T currently visible, it crashes with the message:

Warning: QOpenGLVertexArrayObject::~QOpenGLVertexArrayObjec t() failed to make VAO's context current (opengl/qopenglvertexarrayobject.cpp:370, virtual QOpenGLVertexArrayObject::~QOpenGLVertexArrayObjec t())
Looking through the source code, the destructor of QOpenGLVertexArrayObject contains the following code:

Qt Code:
  1. /*!
  2.   Destroys the QOpenGLVertexArrayObject and the underlying OpenGL resource.
  3. */
  4. QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject()
  5. {
  6. QOpenGLContext* ctx = QOpenGLContext::currentContext();
  7.  
  8. Q_D(QOpenGLVertexArrayObject);
  9. QOpenGLContext *oldContext = 0;
  10. if (d->context && ctx && d->context != ctx) {
  11. oldContext = ctx;
  12. if (d->context->makeCurrent(oldContext->surface())) {
  13. ctx = d->context;
  14. } else {
  15. qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to make VAO's context current");
  16. ctx = 0;
  17. }
  18. }
  19.  
  20. if (ctx)
  21. destroy();
  22.  
  23. if (oldContext) {
  24. if (!oldContext->makeCurrent(oldContext->surface()))
  25. qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to restore current context");
  26. }
  27. }
To copy to clipboard, switch view to plain text mode 

- Is it possible to use QOpenGLVertexArrayObjects in a QGLWidget that's not currently visible and close the program successfully?

- Is this a bug?