Flutter integration with Qt
-
Hi, I have an existing application on C++ with Qt and I wanna extend it by using Flutter. I have tried to use https://github.com/flutter/engine/tree/main/shell/platform/embedder. Currently I am trying to configure engine via FlutterRendererConfig but looks like I should use low level rendering primitives like QOpenGLContext. I have faced an issue with it, because QOpenGLContext cannot be used outside of the thread where it was created. But I need to use it for configuring Flutter engine (code snippet below).
FlutterRendererConfig config = {}; config.type = kOpenGL; config.open_gl.struct_size = sizeof(config.open_gl); config.open_gl.make_current = [](void *userdata) -> bool { QOpenGLContext *context = static_cast<QOpenGLContext *>(userdata); return context->makeCurrent(static_cast<QWindow *>(context->surface())); }; config.open_gl.clear_current = [](void *) -> bool { QOpenGLContext::currentContext()->doneCurrent(); return true; }; config.open_gl.present = [](void *userdata) -> bool { QOpenGLContext *context = static_cast<QOpenGLContext *>(userdata); context->swapBuffers(static_cast<QWindow *>(context->surface())); return true; };
Maybe somebody have done this before and could share a small code snippet with correct configuration? Or there are some ideas how to fix QOpenGLContext limitation?
-
Hi Slandino, I started working a few days ago on a project to mix Qt and flutter. I have already some working code, but it's using offscreen buffers (my final objective is to make a plugin to have a flutter layer in OBS) so I've not even looked on how to render to a window context. But the code may still work for you. I've commited the mess of code I wrote so far to https://github.com/hefsoftware/temp_qt_flutter (it compiles on windows, at least for me). Hope it will give you some help.