I am new in qt, and I am trying to make a toolkit for faster game development. My target platform is MacOSX and Windows. I am working on a game engine called cocos2d-x, which used glfw as desktop opengl window. glfw uses NSGL as opengl context in MacOSX and WGL in windows.

Qt 5.4 introduced a new class called QOpenGLContext to take place of QGLContext. And QOpenGLContext has a new method setNativeHandle which official sai QOpenGLContext is now able to adopt existing native contexts (EGL, GLX, …). This allows interop between Qt and other frameworks, like game engines.

But I tried some ways and all failed.

  1. I try to create a new QOpenGLContext and call setNativeHandle, and set it to setShareContext. Then I create a new QOpenGLWidget and hoping it will use the shareContext, but it is not.
  2. I start with a new QOpenGLWidget, then get its context, and call context's setNativeHandle, but it occur an error.


Now I have 2 ideas, but don't know how to approach
  1. create a QOpenGLContext then adopt glfw's gl context to it, and show it to screen.
  2. create a QOpenGLWidget and change its gl context to glfw's gl context.


Someone knows how to approach this? Or my ideas are totally wrong? Please tell me.
Thanks.