Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qt_add_qml_preview.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qt-add-qml-preview.html
6
\ingroup cmake-commands-qtqml
7
8
\title qt_add_qml_preview
9
\keyword qt_add_qml_preview()
10
11
\summary{Sets up qmlpreview support for an executable that isn't itself a QML module.}
12
13
\cmakecommandsince 6.12
14
\preliminarycmakecommand
15
16
\include cmake-find-package-qml.qdocinc
17
18
\section1 Synopsis
19
20
\badcode
21
qt_add_qml_preview(target)
22
\endcode
23
24
\versionlessCMakeCommandsNote qt6_add_qml_preview()
25
26
\section1 Description
27
28
\c{qt_add_qml_preview()} sets up \l qmlpreview live-reload support for an
29
executable \c target that loads QML from one or more QML modules created with
30
\l qt_add_qml_module(), but which is not itself created by
31
\l qt_add_qml_module(). It creates an additional build target named
32
\c{<target>_qmlpreview} that launches \l qmlpreview on the executable.
33
34
The \c target must be an executable target built by the current project.
35
Passing a library target, or a target imported from another package, results
36
in a configure-time error.
37
38
If \c target is itself a QML module, this command returns immediately without
39
doing anything, because such targets already get \l qmlpreview support as part
40
of \l qt_add_qml_module().
41
42
If \c target links against \c{Qt6::Qml} but no in-project QML modules can be
43
found in its link closure, a warning is emitted at build time, because live
44
reload of QML embedded in Qt resources will not work in that case. If this
45
happens, link the \l qt_add_qml_module() target(s) whose QML files you want to
46
preview to \c target.
47
48
\note To make use of the resulting \c{<target>_qmlpreview} target, \c target
49
itself needs to be built with
50
\l{QML debugging support enabled}{QML debugging infrastructure}, the
51
same requirement as for using the \l qmlpreview tool directly.
52
Moreover, the target is not created when cross-compiling.
53
54
By default, \l qmlpreview support is already set up automatically for every
55
executable target that links against \c{Qt6::Qml}, so you normally don't need
56
to call \c{qt_add_qml_preview()} at all. It is only useful as a per-target
57
override when that automatic behavior has been switched off: calling it enables
58
\l qmlpreview support for \c target even if preview has been disabled globally
59
via the \l QT_QML_NO_QML_PREVIEW variable, or for that target via its
60
\l{cmake-target-property-QT_QML_NO_QML_PREVIEW}{QT_QML_NO_QML_PREVIEW}
61
property.
62
63
\section1 Example
64
65
\badcode
66
qt_add_library(mylib STATIC)
67
qt_add_qml_module(mylib
68
URI My.Lib
69
VERSION 1.0
70
QML_FILES
71
Main.qml
72
)
73
74
qt_add_executable(myapp main.cpp)
75
target_link_libraries(myapp PRIVATE mylib)
76
77
qt_add_qml_preview(myapp)
78
\endcode
79
80
\sa qmlpreview, qt_add_qml_module
81
*/
qtdeclarative
src
qml
doc
src
cmake
qt_add_qml_preview.qdoc
Generated on
for Qt by
1.16.1