Qt 6 是努力使框架更高效,且更易于使用的结果。
为兼容每个发行的所有公共 API,我们试着维护二进制和源代码。但是,为使 Qt 成为更优框架,一些改变是不可避免的。
In this topic we summarize those changes in Qt Quick, and provide guidance to handle them.
The type of
font.weight
has been changed to
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.
font.weight: "Bold"
This code will no longer parse correctly and has to be replaced by its equivalent enum value, as demonstrated below.
font.weight: Font.Bold
In Qt 5, the
名称
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.
FontLoader { id: fontLoader name: "Helvetica" } Text { font.family: fontLoader.name text: "Foobar" }
Instead, use a custom property to store font family names.
property string fontName: "Helvetica" Text { font.family: fontName text: "Foobar" }
In Qt 5.8, OpenGLInfo was deprecated and is removed for Qt 6. Please use GraphicsInfo 代替。
Just like with
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
Qt Shader Tools
module, such as the
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
.qsb
文件。
ShaderEffect
properties
vertexShader
and
fragmentShader
both have a type of
QUrl
now, instead of
QByteArray
. Their behavior is therefore identical to other similar properties, such as
Image.source
. Existing code that refers to files via the
file
or
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
文件:
scheme is therefore optional now.
QQuickItem 's geometryChanged() function was renamed to geometryChange() .
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
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi)
in their main() function.
beforeRenderPassRecording()
signal, that is emitted after clearing, but before rendering Qt Quick's content.
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi)
in their main() function.
initialize(QOpenGLContext*)
函数。
Framebuffer
mode has no effect. It will behave as if the mode was set to the default Image mode.
QSG_NO_DEPTH_BUFFER
is still supported in Qt 6.0, but its usage is recommended to be replaced by calling
setDepthBufferFor2D()
在
QQuickGraphicsConfiguration
that is then associated with the
QQuickWindow
.
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.
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
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
QSG_RHI_BACKEND
environment variable or the
QQuickWindow::setSceneGraphBackend
() function, a platform-specific default is chosen by Qt Quick.
更多信息,拜访 Qt Quick 场景图形 和 Qt Quick 场景图形默认渲染器 页面。