QQuickViewand their associated internal render loops render the Qt Quick scene onto a native window. In some cases, for example when integrating with 3rd party OpenGL renderers, it might be beneficial to get the scene into a texture that can then be used in arbitrary ways by the external rendering engine.
QQuickRenderControlmakes this possible in a hardware accelerated manner, unlike the performance-wise limited alternative of using
When using a
QQuickWindowdoes not have to be shown or even created at all. This means there will not be an underlying native window for it. Instead, the
QQuickWindowinstance is associated with the render control, using the overload of the
QQuickWindowconstructor, and an OpenGL framebuffer object by calling
Management of the context and framebuffer object is up to the application. The context that will be used by Qt Quick must be created before calling
initialize(). The creation of the framebuffer object can be deferred, see below. Qt 5.4 introduces the ability for
QOpenGLContextto adopt existing native contexts. Together with
QQuickRenderControlthis makes it possible to create a
QOpenGLContextthat shares with an external rendering engine’s existing context. This new
QOpenGLContextcan then be used to render the Qt Quick scene into a texture that is accessible by the other engine’s context too.
Loading and instantiation of the QML components happen by using a
QQmlEngine. Once the root object is created, it will need to be parented to the
Applications will usually have to connect to 4 important signals:
sceneGraphInvalidated()When the scenegraph resources are released, the framebuffer object can be destroyed too.
sceneChanged()Indicates that the scene has changed meaning that, before rendering, polishing and synchronizing is also necessary.
To send events, for example mouse or keyboard events, to the scene, use
QQuickWindowinstance as the receiver.
- param parent
QQuickRenderControlobject, with parent object
- Return type
Grabs the contents of the scene and returns it as an image.
Requires the context to be current.
Initializes the scene graph resources. The context
glhas to be the current OpenGL context or null if it is not relevant because a Qt Quick backend other than OpenGL is in use.
Stop rendering and release resources. Requires a current context.
This is the equivalent of the cleanup operations that happen with a real
QQuickWindowwhen the window becomes hidden.
This function is called from the destructor. Therefore there will typically be no need to call it directly. Pay attention however to the fact that this requires the context, that was passed to
initialize(), to be the current one at the time of destroying the
This function does not take QQuickWindow::persistentSceneGraph() or QQuickWindow::persistentOpenGLContext() into account. This means that context-specific resources are always released.
This function should be called as late as possible before
sync(). In a threaded scenario, rendering can happen in parallel with this function.
Prepares rendering the Qt Quick scene outside the gui thread.
targetThreadspecifies the thread on which synchronization and rendering will happen. There is no need to call this function in a single threaded scenario.
Renders the scenegraph using the current context.
Reimplemented in subclasses to return the real window this render control is rendering into.
offsetin non-null, it is set to the offset of the control inside the window.
While not mandatory, reimplementing this function becomes essential for supporting multiple screens with different device pixel ratios and properly positioning popup windows opened from QML. Therefore providing it in subclasses is highly recommended.
- Return type
Returns the real window that
winis being rendered to, if any.
offsetin non-null, it is set to the offset of the rendering inside its window.
- Return type
This function is used to synchronize the QML scene with the rendering scene graph.
If a dedicated render thread is used, the GUI thread should be blocked for the duration of this call.
Returns true if the synchronization changed the scene graph.
© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.