aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/src/qt6-changes.qdoc
blob: 58a7ebb3e1879e0b33c2380d017182548a7a8d05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \page quick-changes-qt6.html
    \title Changes to Qt Quick
    \ingroup changes-qt-5-to-6
    \brief Migrate Qt Quick to Qt 6.

    Qt 6 is a result of the conscious effort to make the framework more
    efficient and easy to use.

    We try to maintain binary and source compatibility for all the public
    APIs in each release. But some changes were inevitable in an effort to
    make Qt a better framework.

    In this topic we summarize those changes in Qt Quick, and provide
    guidance to handle them.


    \section1 Changes to Qt Quick QML Types

    \section2 Changed Type of font.weight

    The type of \c font.weight has been changed to \c int. The pre-defined
    weight classes still exist, but it is now possible to use arbitrary integers
    to select fonts which do not match any of these weight classes. This ensures
    parity with the C++ API, where it has always been possible to express the
    font weight as an arbitrary integer.

    Most code will be unaffected by this change, except in the case where an
    implicit conversion from a string to enum value was used.

    \code
    font.weight: "Bold"
    \endcode

    This code will no longer parse correctly and has to be replaced by its
    equivalent enum value, as demonstrated below.

    \code
    font.weight: Font.Bold
    \endcode

    \section2 FontLoader.name Is Now a Read-Only Property

    In Qt 5, the \c name property of FontLoader was writable and would override
    the source property of the item when set. This caused some confusion as to
    its purpose and could cause undeterministic behavior if there was a race
    condition between the setters for the conflicting properties.

    This means that code such as the following will no longer work.

    \code
    FontLoader {
        id: fontLoader
        name: "Helvetica"
    }

    Text {
        font.family: fontLoader.name
        text: "Foobar"
    }
    \endcode

    Instead, use a custom property to store font family names.

    \code
    property string fontName: "Helvetica"

    Text {
        font.family: fontName
        text: "Foobar"
    }
    \endcode

    \section2 The OpenGLInfo QML Type Is Removed

    In Qt 5.8, OpenGLInfo was deprecated and is removed for Qt 6.
    Please use GraphicsInfo instead.

    \section1 ShaderEffect No Longer Supports Inline GLSL Shader Strings

    Just like with \l{QSGMaterial}{custom materials}, the effects are no longer
    specified in form of GLSL shader strings. Rather, shaders are expected to be
    preprocessed by the tools from the \l{Qt Shader Tools} module, such as the
    \c qsb command line tool, thus ensuring the shader assets are usable
    regardless of which graphics API (Vulkan, Metal, OpenGL, or Direct 3D) is
    used at runtime. ShaderEffect items are expected to reference the resulting
    \c{.qsb} files.

    \section2 ShaderEffect Source Properties Are Now URLs

    The ShaderEffect properties \l{ShaderEffect::vertexShader}{vertexShader} and
    \l{ShaderEffect::fragmentShader}{fragmentShader} both have a type of QUrl
    now, instead of QByteArray. Their behavior is therefore identical to other
    similar properties, such as \l{Image::source}{Image.source}. Existing code
    that refers to files via the \c file or \c qrc scheme will continue to work
    as-is. In addition, this change allows referring to files with a path
    relative to the component's (the .qml file's) location. Specifying the
    \c{file:} scheme is therefore optional now.


    \section1 Changes to Qt Quick C++ APIs

    \section2 Changes to QQuickItem

    QQuickItem's geometryChanged() function was renamed to
    \l{QQuickItem::}{geometryChange()}.

    \section2 Changes to QQuickWidget

    QQuickWidget is functional only when the scenegraph is rendering with
    OpenGL. It will not be functional when using another graphics API, such as
    Vulkan or Metal. Applications relying on QQuickWidget should force the usage
    of OpenGL by calling
    \c{QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi)} in their
    main() function.

    \section2 Changes to QQuick* APIs

    \list

    \li Applications wishing to integrate their own set of Vulkan, Metal, or
    Direct3D rendering commands should be aware of new QQuickWindow signals in
    addition to QQuickWindow::beforeRendering() and afterRendering(). The
    existing Qt 5 pattern of connecting to just beforeRendering or
    afterRendering is often not sufficient anymore on its own, and will likely
    need to be complemented by connecting to additional signals, such as
    \l{QQuickWindow::beforeRenderPassRecording()}{beforeRenderPassRecording()}
    or \l{QQuickWindow::afterRenderPassRecording()}{afterRenderPassRecording()}.

    \li Applications that rely on the QQuickWindow::beforeRendering() or
    afterRendering() signals to issue their own set of OpenGL rendering commands
    should call QQuickWindow::beginExternalCommands() before, and
    QQuickWindow::endExternalCommands() after, the OpenGL calls. This ensures
    that state changes made by the application code does not lead to confusion
    with regards to the scene graph renderer's own cached state. Note however,
    that, just like in Qt 5, changing OpenGL 3.x or 4.x state that is not used
    by the Qt Quick renderer can still lead to unexpected issues, so therefore
    application are advised to reset any such OpenGL state to the default value
    before returning from the slots or lambdas connected to these signals.

    \li The existing QQuickWindow::setRenderTarget() overloads, and the
    related getters, are removed and replaced by a new function taking a
    QQuickRenderTarget. Applications performing redirected rendering in
    combination with QQuickRenderControl are now expected to use this new
    function to specify the render target in a manner that is not tied to
    OpenGL.

    \li The QQuickWindow::setSceneGraphBackend() overload taking a
    QSGRendererInterface::GraphicsApi argument has been renamed to
    \l{QQuickWindow::setGraphicsApi()}{setGraphicsApi()}.

    \li The QQuickWindow functions setPersistentOpenGLContext and
    isPersistentOpenGLContext are renamed, and are now
    QQuickWindow::setPersistentGraphics() and
    QQuickWindow::isPersistentGraphics().

    \li setClearBeforeRendering() and clearBeforeRendering() have been removed
    from QQuickWindow. There is no option for skipping the color buffer clearing
    in Qt 6. Calling setClearBeforeRendering() was often necessary in Qt 5 in
    combination with underlays, to prevent Qt Quick from clearing the content
    rendered into the color buffer. In Qt 6, there is a more robust approach:
    connecting to the \c beforeRenderPassRecording() signal,
    that is emitted after clearing, but before rendering Qt Quick's content.


    \li The QQuickWindow::openglContext() function has been removed. When the
    application has ensured the scene graph is using OpenGL for rendering, it
    can query the QOpenGLContext from QSGRendererInterface::getResource().

    \li The QQuickWindow::openglContextCreated() signal has been removed.

    \li The deprecated QQuickWindow::createTextureFromId() function has been
    removed. Instead, use the fromNative() function from
    QPlatformInterface::QSGOpenGLTexture, QPlatformInterface::QSGVulkanTexture,
    QPlatformInterface::QSGD3D11Texture, or QPlatformInterface::QSGMetalTexture.

    \li The QQuickFramebufferObject class is available with an unchanged API,
    but is only functional when the scenegraph is rendering with OpenGL. It will
    not be functional when using another graphics API, such as Vulkan or Metal.
    Applications relying on QQuickFramebufferObject should force the usage of
    OpenGL by calling
    \c{QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi)} in their
    main() function.

    \li QQuickRenderControl has a slightly changed API: grab() is now
    removed, use QQuickWindow::grabWindow() instead, where applicable. The
    initialize() function no longer takes a QOpenGLContext. Applications are
    now also required to call QQuickRenderControl::beginFrame() and
    QQuickRenderControl::endFrame() as appropriate. When multisampling is
    desired, the new function QQuickRenderControl::setSamples() must be
    called to indicate the sample count.

    \li Applications wishing to perform Qt Quick rendering in combination
    with an existing native graphics device or context object must take the
    new QQuickWindow::setGraphicsDevice() function into use as
    QQuickRenderControl no longer provides the
    \c{initialize(QOpenGLContext*)} function.

    \li Setting QQuickPaintedItem and Context2D to \c Framebuffer mode has
    no effect. It will behave as if the mode was set to the default Image
    mode.

    \li The environment variable \c{QSG_NO_DEPTH_BUFFER} is still supported in
    Qt 6.0, but its usage is recommended to be replaced by calling
    \l{QQuickGraphicsConfiguration::setDepthBufferFor2D()}{setDepthBufferFor2D()}
    on a QQuickGraphicsConfiguration that is then associated with the
    QQuickWindow.

    \endlist

    \section1 Changes to QSG* APIs

    \list

    \li QSGMaterialShader has a changed interface. Implementations should
    not rely on OpenGL anymore, and cannot assume that functions, such as
    the now-removed updateState(), are called with a QOpenGLContext
    current. In the new, data-oriented interface updateState() is replaced
    by \l{QSGMaterialShader::updateUniformData()}{updateUniformData()},
    \l{QSGMaterialShader::updateSampledImage()}{updateSampledImage()}, and
    \l{QSGMaterialShader::updateGraphicsPipelineState()}{updateGraphicsPipelineState()}.
    Instead of GLSL shader code provided as strings, shaders are now
    expected to be preprocessed by the tools from the Qt Shader Tools
    module, such as the \c qsb command line tool, thus ensuring the shader
    assets are usable regardless of which graphics API (Vulkan, Metal,
    OpenGL, or Direct 3D) is used at run time.

    \li QSGEngine has been removed. In the unlikely case of an application
    utilizing this class, it is recommended to port to using
    QQuickRenderControl instead.

    \li QSGAbstractRenderer is no longer public. The usage of this class made
    sense only in combination with QSGEngine, and with that class being
    removed QSGAbstractRenderer has been moved back to private.

    \li The QSGSimpleMaterial convenience class has been
    removed. Applications are expected to use the revised, OpenGL-independent
    QSGMaterial APIs instead.

    \li To access the underlying native texture object for a QSGTexture,
    textureId() is no longer available. Instead, use
    QSGTexture::platformInterface() with QPlatformInterface::QSGOpenGLTexture,
    QPlatformInterface::QSGVulkanTexture, QPlatformInterface::QSGD3D11Texture,
    or QPlatformInterface::QSGMetalTexture.

    \li Subclasses of QSGImageNode are now required to override new
    additional virtuals, such as setAnisotropyLevel() and anisotropyLevel().

    \li Subclasses of QSGTexture will likely need to be redesigned. Some of
    the OpenGL-specific virtual functions, such as bind() or
    updateBindOptions(), are no longer present, while there are new virtuals
    that are mandatory to implement, such as
    \l{QSGTexture::comparisonKey()}{comparisonKey()}.

    \endlist

    \section1 Changes to OpenGL Use in Qt Quick

    While it will present no breaks for many applications, application
    developers should be aware that, OpenGL is not always the default choice
    anymore for Qt Quick rendering in Qt 6. Unless the \c software backend is
    used, a Qt Quick application could use OpenGL, Vulkan, Metal, or Direct3D 11
    at runtime. When no explicit request is made, either via the
    \c QSG_RHI_BACKEND environment variable or the
    QQuickWindow::setSceneGraphBackend() function, a platform-specific
    default is chosen by Qt Quick.

    For more information, visit the \l{Qt Quick Scene Graph} and the
    \l{Qt Quick Scene Graph Default Renderer} pages.


*/