summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-01-24 09:48:14 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-02 10:56:31 +0000
commit4ef78d5bbf021ba0723f6cc14aba8ef65d3218c5 (patch)
treea4f0c6598be6b4cc53322414f2467e7682b0fb60
parent6992ba6c3ddc1ad517b6f88ff1e14e1471d735f5 (diff)
downloadqttools-4ef78d5bbf021ba0723f6cc14aba8ef65d3218c5.tar.gz
Qt Designer examples: Add explanation of CMake project files
Task-number: QTBUG-110447 Change-Id: I36769acc50921c2e6af33288b8e291b56328ddc7 Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io> (cherry picked from commit 64fab45f2696a4a54aa07136d6100b47454c488d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/designer/containerextension/CMakeLists.txt11
-rw-r--r--examples/designer/containerextension/containerextension.pro3
-rw-r--r--examples/designer/customwidgetplugin/CMakeLists.txt11
-rw-r--r--examples/designer/customwidgetplugin/customwidgetplugin.pro15
-rw-r--r--examples/designer/doc/src/containerextension.qdoc83
-rw-r--r--examples/designer/doc/src/customwidgetplugin.qdoc88
-rw-r--r--examples/designer/doc/src/taskmenuextension.qdoc66
-rw-r--r--examples/designer/doc/src/worldtimeclockplugin.qdoc94
-rw-r--r--examples/designer/taskmenuextension/CMakeLists.txt11
-rw-r--r--examples/designer/taskmenuextension/taskmenuextension.pro11
-rw-r--r--examples/designer/worldtimeclockplugin/CMakeLists.txt11
-rw-r--r--examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro13
12 files changed, 252 insertions, 165 deletions
diff --git a/examples/designer/containerextension/CMakeLists.txt b/examples/designer/containerextension/CMakeLists.txt
index 267bfebaa..03344ef3a 100644
--- a/examples/designer/containerextension/CMakeLists.txt
+++ b/examples/designer/containerextension/CMakeLists.txt
@@ -3,30 +3,39 @@ project(containerextension LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
+#! [0]
find_package(Qt6 REQUIRED COMPONENTS Core Designer Gui Widgets)
qt_add_plugin(containerextension)
+#! [0]
+
+#! [1]
target_sources(containerextension PRIVATE
multipagewidget.cpp multipagewidget.h
multipagewidgetcontainerextension.cpp multipagewidgetcontainerextension.h
multipagewidgetextensionfactory.cpp multipagewidgetextensionfactory.h
multipagewidgetplugin.cpp multipagewidgetplugin.h
)
+#! [1]
set_target_properties(containerextension PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
+#! [2]
target_link_libraries(containerextension PUBLIC
Qt::Core
Qt::Designer
Qt::Gui
Qt::Widgets
)
+#! [2]
if(QT6_INSTALL_PREFIX)
+#! [3]
set(INSTALL_EXAMPLEDIR "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}/designer")
+#! [3]
else()
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
@@ -34,8 +43,10 @@ else()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/plugins/designer")
endif()
+#! [4]
install(TARGETS containerextension
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
+#! [4]
diff --git a/examples/designer/containerextension/containerextension.pro b/examples/designer/containerextension/containerextension.pro
index 39b6dc2a2..f4a6fb32d 100644
--- a/examples/designer/containerextension/containerextension.pro
+++ b/examples/designer/containerextension/containerextension.pro
@@ -14,9 +14,10 @@ CONFIG += plugin
TARGET = $$qtLibraryTarget($$TARGET)
+#! [3]
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
-
+#! [3]
}
#! [1]
diff --git a/examples/designer/customwidgetplugin/CMakeLists.txt b/examples/designer/customwidgetplugin/CMakeLists.txt
index 6174d4d66..91365b2fb 100644
--- a/examples/designer/customwidgetplugin/CMakeLists.txt
+++ b/examples/designer/customwidgetplugin/CMakeLists.txt
@@ -3,28 +3,37 @@ project(customwidgetplugin LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
+#! [0]
find_package(Qt6 REQUIRED COMPONENTS Core Gui UiPlugin Widgets)
qt_add_plugin(customwidgetplugin)
+#! [0]
+
+#! [1]
target_sources(customwidgetplugin PRIVATE
analogclock.cpp analogclock.h
customwidgetplugin.cpp customwidgetplugin.h
)
+#! [1]
set_target_properties(customwidgetplugin PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
+#! [2]
target_link_libraries(customwidgetplugin PUBLIC
Qt::Core
Qt::Gui
Qt::UiPlugin
Qt::Widgets
)
+#! [2]
if(QT6_INSTALL_PREFIX)
+#! [3]
set(INSTALL_EXAMPLEDIR "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}/designer")
+#! [3]
else()
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
@@ -32,8 +41,10 @@ else()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/plugins/designer")
endif()
+#! [4]
install(TARGETS customwidgetplugin
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
+#! [4]
diff --git a/examples/designer/customwidgetplugin/customwidgetplugin.pro b/examples/designer/customwidgetplugin/customwidgetplugin.pro
index 1447acdc4..92abd7529 100644
--- a/examples/designer/customwidgetplugin/customwidgetplugin.pro
+++ b/examples/designer/customwidgetplugin/customwidgetplugin.pro
@@ -1,6 +1,6 @@
-#! [0]
+#! [1]
QT += widgets uiplugin
-#! [0]
+#! [1]
QTDIR_build {
# This is only for the Qt build. Do not use externally. We mean it.
@@ -11,22 +11,23 @@ CONFIG += install_ok
} else {
# Public example:
-#! [2]
+#! [0]
CONFIG += plugin
TEMPLATE = lib
-#! [2]
+#! [0]
+#! [3]
TARGET = $$qtLibraryTarget($$TARGET)
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
-
+#! [3]
}
-#! [3]
+#! [2]
HEADERS = analogclock.h \
customwidgetplugin.h
SOURCES = analogclock.cpp \
customwidgetplugin.cpp
OTHER_FILES += analogclock.json
-#! [3]
+#! [2]
diff --git a/examples/designer/doc/src/containerextension.qdoc b/examples/designer/doc/src/containerextension.qdoc
index b20093a53..80c965a6f 100644
--- a/examples/designer/doc/src/containerextension.qdoc
+++ b/examples/designer/doc/src/containerextension.qdoc
@@ -59,41 +59,32 @@
extension.
\endlist
- The project file for custom widget plugins needs some additional
+ Project files for custom widget plugins need some additional
information to ensure that they will work within \QD. For example,
custom widget plugins rely on components supplied with \QD, and
- this must be specified in the project file that we use. We will
- first take a look at the plugin's project file.
+ this must be specified in the project files that we use. We will
+ first take a look at the plugin's project files.
Then we will continue by reviewing the \c MultiPageWidgetPlugin
class, and take a look at the \c MultiPageWidgetExtensionFactory
and \c MultiPageWidgetContainerExtension classes. Finally, we will
take a quick look at the \c MultiPageWidget class definition.
- \section1 The Project File: containerextension.pro
+ \section1 Project files
- The project file must contain some additional information to
- ensure that the plugin will work as expected:
+ \section2 CMake
- \snippet containerextension/containerextension.pro 0
- \snippet containerextension/containerextension.pro 1
-
- The \c TEMPLATE variable's value makes \c qmake create the custom
- widget as a library. Later, we will ensure that the widget will be
- recognized as a plugin by Qt by using the Q_PLUGIN_METADATA() macro
- to export the relevant widget information.
+ The project files need to state that a plugin linking
+ to the \QD libraries is to be built:
- The \c CONFIG variable is set to \c plugin, which ensures that \c qmake
- considers the custom widget a plugin library.
-
- The \c QT variable contains the value \c designer. Since the plugin uses
- components supplied with \QD that require linkage, this value ensures
- that our plugin links against \QD's library (\c libQtDesigner.so).
+ \snippet containerextension/CMakeLists.txt 0
+ \codeline
+ \snippet containerextension/CMakeLists.txt 2
- The header and source files for the widget are declared in the
- usual way:
+ The following example shows how to add the header and source files of the
+ widget:
- \snippet containerextension/containerextension.pro 2
+ \snippet containerextension/CMakeLists.txt 1
We provide an implementation of the plugin interface so that \QD
can use the custom widget. In this particular example we also
@@ -105,21 +96,33 @@
target path for the project and adding it to the list of items to
install:
- \snippet doc/snippets/doc_src_examples_containerextension.pro 0
+ \snippet containerextension/CMakeLists.txt 3
+ \snippet containerextension/CMakeLists.txt 4
- The container extension is created as a library, and will be
+ The container extension is created as a library. It will be
installed alongside the other \QD plugins when the project is
- installed (using \c{make install} or an equivalent installation
+ installed (using \c{ninja install} or an equivalent installation
procedure).
- Note that if you want the plugins to appear in a Visual Studio
- integration, the plugins must be built in release mode and their
- libraries must be copied into the plugin directory in the install
- path of the integration (for an example, see \c {C:/program
- files/trolltech as/visual studio integration/plugins}).
+ For more information about plugins, see the
+ \l {How to Create Qt Plugins} documentation.
+
+ \section2 qmake
+
+ The following example shows how to link a plugin to the \QD libraries:
+
+ \snippet containerextension/containerextension.pro 0
+ \codeline
+ \snippet containerextension/containerextension.pro 1
- For more information about plugins, see the \l {How to Create Qt
- Plugins} documentation.
+ The following example shows how to add the header and source files of the
+ widget:
+
+ \snippet containerextension/containerextension.pro 2
+
+ The following example shows how to install a plugin to the \QD's plugin path:
+
+ \snippet containerextension/containerextension.pro 3
\section1 MultiPageWidgetPlugin Class Definition
@@ -160,6 +163,14 @@
enables \QD to use qobject_cast() to query for supported
interfaces using nothing but a QObject pointer.
+ To ensure that Qt recognizes the widget as a plugin, export relevant
+ information about the widget by adding the \c Q_PLUGIN_METADATA() macro:
+
+ \snippet containerextension/multipagewidgetplugin.h 1
+
+ With this macro, \QD can access and construct the custom widget.
+ Without this macro, there is no way for \QD to use the widget.
+
\section1 MultiPageWidgetPlugin Class Implementation
The MultiPageWidgetPlugin class implementation is in most parts
@@ -310,14 +321,6 @@
page; any inital pages of a multi-page widget must be specified
within this function.
- \snippet containerextension/multipagewidgetplugin.h 1
-
- Remember to use the Q_PLUGIN_METADATA() macro to export the
- MultiPageWidgetPlugin class for use with Qt's plugin handling
- classes: This macro ensures that \QD can access and construct the
- custom widget. Without this macro, there is no way for \QD to use
- the widget.
-
\section1 MultiPageWidgetExtensionFactory Class Definition
The \c MultiPageWidgetExtensionFactory class inherits QExtensionFactory
diff --git a/examples/designer/doc/src/customwidgetplugin.qdoc b/examples/designer/doc/src/customwidgetplugin.qdoc
index b7ab1e8a0..3ce9285c8 100644
--- a/examples/designer/doc/src/customwidgetplugin.qdoc
+++ b/examples/designer/doc/src/customwidgetplugin.qdoc
@@ -21,59 +21,68 @@
example, we reuse the \l{widgets/analogclock}{Analog Clock example} for
convenience.
- Since custom widgets plugins rely on components supplied with \QD, the
- project file that we use needs to contain information about \QD's
- library components:
+ \section1 Project files
- \snippet customwidgetplugin/customwidgetplugin.pro 2
- \snippet customwidgetplugin/customwidgetplugin.pro 0
+ \section2 CMake
- The \c TEMPLATE variable's value makes \c qmake create the custom
- widget as a library. Later, we will ensure that the widget will be
- recognized as a plugin by Qt by using the Q_PLUGIN_METADATA() macro
- to export the relevant widget information.
+ The project files need to state that a plugin linking
+ to the \QD libraries is to be built:
+ \snippet customwidgetplugin/CMakeLists.txt 0
+ \codeline
+ \snippet customwidgetplugin/CMakeLists.txt 2
- The \c CONFIG variable is set to \c plugin, which ensures that \c qmake
- considers the custom widget a plugin library.
+ The link libraries list specifies \c Qt::UiPlugin. This indicates that
+ the plugin uses the abstract interfaces QDesignerCustomWidgetInterface
+ and QDesignerCustomWidgetCollectionInterface only and has no linkage
+ to the \QD libraries. When accessing other interfaces of \QD that have
+ linkage, \c Designer should be used instead; this ensures that the plugin
+ dynamically links to the \QD libraries and has a run-time dependency on
+ them.
- The \c QT variable contains the keyword \c uiplugin. This plugin type
- provides a factory function for custom widget creation by implementing
- the abstract interfaces QDesignerCustomWidgetInterface or
- QDesignerCustomWidgetCollectionInterface, suitable for use with
- QUiLoader. It does not have a dependency on the \QD libraries.
- Plugins accessing other interfaces of \QD to implement container extensions
- or other \QD specific functionality follow different rules and are covered
- by other examples.
+ The following example shows how to add the header and source files of the
+ widget:
- The header and source files for the widget are declared in the usual way,
- and we provide an implementation of the plugin interface so that \QD can
- use the custom widget:
+ \snippet customwidgetplugin/CMakeLists.txt 1
- \snippet customwidgetplugin/customwidgetplugin.pro 3
+ We provide an implementation of the plugin interface so that \QD
+ can use the custom widget.
It is also important to ensure that the plugin is installed in a
location that is searched by \QD. We do this by specifying a
target path for the project and adding it to the list of items to
install:
- \snippet doc/snippets/doc_src_examples_customwidgetplugin.pro 0
+ \snippet customwidgetplugin/CMakeLists.txt 3
+ \snippet customwidgetplugin/CMakeLists.txt 4
+
+ The custom widget is created as a library. It will be
+ installed alongside the other \QD plugins when the project is
+ installed (using \c{ninja install} or an equivalent installation
+ procedure).
+
+ For more information about plugins, see the
+ \l {How to Create Qt Plugins} documentation.
+
+ \section2 qmake
+
+ The following example shows how to link a plugin to the \QD libraries:
- The custom widget is created as a library, and will be installed
- alongside the other \QD plugins when the project is installed
- (using \c{make install} or an equivalent installation procedure).
- Later, we will ensure that it is recognized as a plugin by \QD by
- using the Q_PLUGIN_METADATA() macro to export the relevant widget
- information.
+ \snippet customwidgetplugin/customwidgetplugin.pro 0
+ \codeline
+ \snippet customwidgetplugin/customwidgetplugin.pro 1
+
+ The \c QT variable contains the keyword \c uiplugin, which is
+ the equivalent of the \c Qt::UiPlugin library.
- Note that if you want the plugins to appear in a Visual Studio
- integration, the plugins must be built in release mode and their
- libraries must be copied into the plugin directory in the install
- path of the integration (for an example, see \c {C:/program
- files/trolltech as/visual studio integration/plugins}).
+ The following example shows how to add the header and source files of the
+ widget:
+
+ \snippet customwidgetplugin/customwidgetplugin.pro 2
- For more information about plugins, see the \l {How to
- Create Qt Plugins} documentation.
+ The following example shows how to install a plugin to the \QD's plugin path:
+
+ \snippet customwidgetplugin/customwidgetplugin.pro 3
\section1 AnalogClock Class Definition and Implementation
@@ -88,7 +97,10 @@
The \c AnalogClock class is exposed to \QD through the \c
AnalogClockPlugin class. This class inherits from both QObject and
the QDesignerCustomWidgetInterface class, and implements an
- interface defined by QDesignerCustomWidgetInterface:
+ interface defined by QDesignerCustomWidgetInterface.
+
+ To ensure that Qt recognizes the widget as a plugin, export relevant
+ information about the widget by adding the \c Q_PLUGIN_METADATA() macro:
\snippet customwidgetplugin/customwidgetplugin.h 0
diff --git a/examples/designer/doc/src/taskmenuextension.qdoc b/examples/designer/doc/src/taskmenuextension.qdoc
index f3e92ce86..440c2b28b 100644
--- a/examples/designer/doc/src/taskmenuextension.qdoc
+++ b/examples/designer/doc/src/taskmenuextension.qdoc
@@ -71,30 +71,21 @@
TicTacToeDialog class before we take a quick look at the \c
TicTacToe widget's class definition.
- \section1 The Project File: taskmenuextension.pro
+ \section1 Project files
- The project file must contain some additional information to
- ensure that the plugin will work as expected:
+ \section2 CMake
- \snippet taskmenuextension/taskmenuextension.pro 0
- \snippet taskmenuextension/taskmenuextension.pro 1
-
- The \c TEMPLATE variable's value makes \c qmake create the custom
- widget as a library. Later, we will ensure that the widget will be
- recognized as a plugin by Qt by using the Q_PLUGIN_METADATA() macro to
- export the relevant widget information.
-
- The \c CONFIG variable is set to \c plugin, which ensures that \c qmake
- considers the custom widget a plugin library.
+ The project files need to state that a plugin linking
+ to the \QD libraries is to be built:
- The \c QT variable contains the value \c designer. Since the plugin uses
- components supplied with \QD that require linkage, this value ensures
- that our plugin links against \QD's library (\c libQtDesigner.so).
+ \snippet taskmenuextension/CMakeLists.txt 0
+ \codeline
+ \snippet taskmenuextension/CMakeLists.txt 2
- The header and source files for the widget are declared in the
- usual way:
+ The following example shows how to add the header and source files of the
+ widget:
- \snippet taskmenuextension/taskmenuextension.pro 2
+ \snippet taskmenuextension/CMakeLists.txt 1
We provide an implementation of the plugin interface so that \QD
can use the custom widget. In this particular example we also
@@ -106,21 +97,33 @@
target path for the project and adding it to the list of items to
install:
- \snippet doc/snippets/doc_src_examples_taskmenuextension.pro 0
+ \snippet taskmenuextension/CMakeLists.txt 3
+ \snippet taskmenuextension/CMakeLists.txt 4
- The task menu extension is created as a library, and will be
+ The task menu extension is created as a library. It will be
installed alongside the other \QD plugins when the project is
- installed (using \c{make install} or an equivalent installation
+ installed (using \c{ninja install} or an equivalent installation
procedure).
- Note that if you want the plugins to appear in a Visual Studio
- integration, the plugins must be built in release mode and their
- libraries must be copied into the plugin directory in the install
- path of the integration (for an example, see \c {C:/program
- files/trolltech as/visual studio integration/plugins}).
+ For more information about plugins, see the
+ \l {How to Create Qt Plugins} documentation.
+
+ \section2 qmake
- For more information about plugins, see the \l {How to Create Qt
- Plugins} documentation.
+ The following example shows how to link a plugin to the \QD libraries:
+
+ \snippet taskmenuextension/taskmenuextension.pro 0
+ \codeline
+ \snippet taskmenuextension/taskmenuextension.pro 1
+
+ The following example shows how to add the header and source files of the
+ widget:
+
+ \snippet taskmenuextension/taskmenuextension.pro 2
+
+ The following example shows how to install a plugin to the \QD's plugin path:
+
+ \snippet taskmenuextension/taskmenuextension.pro 3
\section1 TicTacToePlugin Class Definition
@@ -129,7 +132,10 @@
{customwidgetplugin}{Custom Widget Plugin} example's
plugin class which is explained in detail. The only part of the
class definition that is specific to this particular custom widget
- is the class name:
+ is the class name.
+
+ To ensure that Qt recognizes the widget as a plugin, export relevant
+ information about the widget by adding the \c Q_PLUGIN_METADATA() macro:
\snippet taskmenuextension/tictactoeplugin.h 0
diff --git a/examples/designer/doc/src/worldtimeclockplugin.qdoc b/examples/designer/doc/src/worldtimeclockplugin.qdoc
index 81bb90126..25198f261 100644
--- a/examples/designer/doc/src/worldtimeclockplugin.qdoc
+++ b/examples/designer/doc/src/worldtimeclockplugin.qdoc
@@ -79,7 +79,10 @@
{customwidgetplugin}{Custom Widget Plugin} example's
plugin class which is explained in detail. The only part of the
class definition that is specific to this particular custom widget
- is the class name:
+ is the class name.
+
+ To ensure that Qt recognizes the widget as a plugin, export relevant
+ information about the widget by adding the \c Q_PLUGIN_METADATA() macro:
\snippet worldtimeclockplugin/worldtimeclockplugin.h 0
@@ -113,52 +116,67 @@
Without this macro, there is no way for Qt Designer to use the
widget.
- \section1 The Project File: worldtimeclockplugin.pro
-
- The project file for custom widget plugins needs some additional
- information to ensure that they will work as expected within \QD:
+ \section1 Project files
+ \section2 CMake
- \snippet worldtimeclockplugin/worldtimeclockplugin.pro 0
- \snippet worldtimeclockplugin/worldtimeclockplugin.pro 1
+ The project files need to state that a plugin linking
+ to the \QD libraries is to be built:
- The \c TEMPLATE variable's value in conjunction with the keyword
- \c plugin in the \c CONFIG variable make \c qmake create the custom
- widget as a plugin library.
+ \snippet worldtimeclockplugin/CMakeLists.txt 0
+ \codeline
+ \snippet worldtimeclockplugin/CMakeLists.txt 2
- The \c QT variable contains the keyword \c uiplugin. This plugin type
- provides a factory function for custom widget creation by implementing
- the abstract interfaces QDesignerCustomWidgetInterface or
- QDesignerCustomWidgetCollectionInterface, suitable for use with
- QUiLoader. It does not have a dependency on the \QD libraries.
- Plugins accessing other interfaces of \QD to implement container extensions
- or other \QD specific functionality follow different rules and are covered
- by other examples.
+ The link libraries list specifies \c Qt::UiPlugin. This indicates that
+ the plugin uses the abstract interfaces QDesignerCustomWidgetInterface
+ and QDesignerCustomWidgetCollectionInterface only and has no linkage
+ to the \QD libraries. When accessing other interfaces of \QD that have
+ linkage, \c Designer should be used instead; this ensures that the plugin
+ dynamically links to the \QD libraries and has a run-time dependency on
+ them.
The header and source files for the widget are declared in the
- usual way, and in addition we provide an implementation of the
- plugin interface so that \QD can use the custom widget.
+ usual way:
- \snippet worldtimeclockplugin/worldtimeclockplugin.pro 2
+ \snippet worldtimeclockplugin/CMakeLists.txt 1
+
+ We provide an implementation of the plugin interface so that \QD
+ can use the custom widget. In this particular example we also
+ provide implementations of the container extension interface and
+ the extension factory.
+
+ It is important to ensure that the plugin is installed in a
+ location that is searched by \QD. We do this by specifying a
+ target path for the project and adding it to the list of items to
+ install:
+
+ \snippet worldtimeclockplugin/CMakeLists.txt 3
+ \snippet worldtimeclockplugin/CMakeLists.txt 4
- It is important to ensure that the plugin is installed in a location that
- is searched by \QD. We do this by specifying a target path for the project
- and adding it to the list of items to install:
+ The custom widget is created as a library. It will be
+ installed alongside the other \QD plugins when the project is
+ installed (using \c{ninja install} or an equivalent installation
+ procedure).
- \snippet doc/snippets/doc_src_examples_worldtimeclockplugin.pro 0
+ For more information about plugins, see the
+ \l {How to Create Qt Plugins} documentation.
- The custom widget is created as a library, and will be installed
- alongside the other \QD plugins when the project is installed
- (using \c{make install} or an equivalent installation procedure).
- Later, we will ensure that it is recognized as a plugin by \QD by
- using the Q_PLUGIN_METADATA() macro to export the relevant widget
- information.
+ \section2 qmake
+
+ The following example shows how to link a plugin to the \QD libraries:
+
+ \snippet worldtimeclockplugin/worldtimeclockplugin.pro 0
+ \codeline
+ \snippet worldtimeclockplugin/worldtimeclockplugin.pro 1
+
+ The \c QT variable contains the keyword \c uiplugin, which is
+ the equivalent of the \c Qt::UiPlugin library.
+
+ The following example shows how to add the header and source files of the
+ widget:
+
+ \snippet worldtimeclockplugin/worldtimeclockplugin.pro 2
- Note that if you want the plugins to appear in a Visual Studio
- integration, the plugins must be built in release mode and their
- libraries must be copied into the plugin directory in the install
- path of the integration (for an example, see \c {C:/program
- files/trolltech as/visual studio integration/plugins}).
+ The following example shows how to install a plugin to the \QD's plugin path:
- For more information about plugins, see the \l {How to Create Qt
- Plugins} document.
+ \snippet worldtimeclockplugin/worldtimeclockplugin.pro 3
*/
diff --git a/examples/designer/taskmenuextension/CMakeLists.txt b/examples/designer/taskmenuextension/CMakeLists.txt
index 9e97bd1b4..17301ccc9 100644
--- a/examples/designer/taskmenuextension/CMakeLists.txt
+++ b/examples/designer/taskmenuextension/CMakeLists.txt
@@ -3,30 +3,39 @@ project(taskmenuextension LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
+#! [0]
find_package(Qt6 REQUIRED COMPONENTS Core Designer Gui Widgets)
qt_add_plugin(taskmenuextension)
+#! [0]
+
+#! [1]
target_sources(taskmenuextension PRIVATE
tictactoe.cpp tictactoe.h
tictactoedialog.cpp tictactoedialog.h
tictactoeplugin.cpp tictactoeplugin.h
tictactoetaskmenu.cpp tictactoetaskmenu.h
)
+#! [1]
set_target_properties(taskmenuextension PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
+#! [2]
target_link_libraries(taskmenuextension PUBLIC
Qt::Core
Qt::Designer
Qt::Gui
Qt::Widgets
)
+#! [2]
if(QT6_INSTALL_PREFIX)
+#! [3]
set(INSTALL_EXAMPLEDIR "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}/designer")
+#! [3]
else()
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
@@ -34,8 +43,10 @@ else()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/plugins/designer")
endif()
+#! [4]
install(TARGETS taskmenuextension
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
+#! [4]
diff --git a/examples/designer/taskmenuextension/taskmenuextension.pro b/examples/designer/taskmenuextension/taskmenuextension.pro
index 71a3806d6..d71a3b93b 100644
--- a/examples/designer/taskmenuextension/taskmenuextension.pro
+++ b/examples/designer/taskmenuextension/taskmenuextension.pro
@@ -1,6 +1,6 @@
-#! [0]
+#! [1]
QT += widgets designer
-#! [0]
+#! [1]
QTDIR_build {
# This is only for the Qt build. Do not use externally. We mean it.
@@ -11,16 +11,17 @@ CONFIG += install_ok
} else {
# Public example:
-#! [1]
+#! [0]
TEMPLATE = lib
CONFIG += plugin
-#! [1]
+#! [0]
TARGET = $$qtLibraryTarget($$TARGET)
+#! [3]
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
-
+#! [3]
}
#! [2]
diff --git a/examples/designer/worldtimeclockplugin/CMakeLists.txt b/examples/designer/worldtimeclockplugin/CMakeLists.txt
index 114f4346a..8ae125320 100644
--- a/examples/designer/worldtimeclockplugin/CMakeLists.txt
+++ b/examples/designer/worldtimeclockplugin/CMakeLists.txt
@@ -3,28 +3,37 @@ project(worldtimeclockplugin LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
+#! [0]
find_package(Qt6 REQUIRED COMPONENTS Core Gui UiPlugin Widgets)
qt_add_plugin(worldtimeclockplugin)
+#! [0]
+
+#! [1]
target_sources(worldtimeclockplugin PRIVATE
worldtimeclock.cpp worldtimeclock.h
worldtimeclockplugin.cpp worldtimeclockplugin.h
)
+#! [1]
set_target_properties(worldtimeclockplugin PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
+#! [2]
target_link_libraries(worldtimeclockplugin PUBLIC
Qt::Core
Qt::Gui
Qt::UiPlugin
Qt::Widgets
)
+#! [2]
if(QT6_INSTALL_PREFIX)
+#! [3]
set(INSTALL_EXAMPLEDIR "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}/designer")
+#! [3]
else()
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
@@ -32,8 +41,10 @@ else()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/plugins/designer")
endif()
+#! [4]
install(TARGETS worldtimeclockplugin
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
+#! [4]
diff --git a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro
index b6332ce46..dc9331be4 100644
--- a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro
+++ b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro
@@ -1,6 +1,6 @@
-#! [0]
+#! [1]
QT += widgets uiplugin
-#! [0]
+#! [1]
QTDIR_build {
# This is only for the Qt build. Do not use externally. We mean it.
@@ -12,14 +12,15 @@ CONFIG += install_ok
# Public example:
TARGET = $$qtLibraryTarget($$TARGET)
-#! [1]
-CONFIG += plugin
+#! [0]
TEMPLATE = lib
-#! [1]
+CONFIG += plugin
+#! [0]
+#! [3]
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
-
+#! [3]
}
#! [2]