Move the uitools multipleinheritance example to calculatorform_mi

It illustrates how to use multipleinheritance from Ui struct and widget
and is not really related to UiTools.

Task-number: QTBUG-110447
Pick-to: 6.5
Change-Id: If6b61c76ea0ac07b935f1e0a8ee02a2e7179cdc3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Friedemann Kleint
2023-02-10 10:12:35 +01:00
parent ac8cc15fe7
commit db7a30bd1d
15 changed files with 26 additions and 27 deletions
+1
View File
@@ -7,6 +7,7 @@ qt_exclude_tool_directories_from_default_target(
)
qt_internal_add_example(calculatorform)
qt_internal_add_example(calculatorform_mi)
if(QT_BUILD_SHARED_LIBS AND NOT solaris-cc_x_)
qt_internal_add_example(calculatorbuilder)
endif()
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(multipleinheritance LANGUAGES CXX)
project(calculatorform_mi LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
@@ -11,27 +11,27 @@ if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/uitools/multipleinheritance")
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/designer/calculatorform_mi")
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_add_executable(multipleinheritance
qt_add_executable(calculatorform_mi
calculatorform.cpp calculatorform.h calculatorform.ui
main.cpp
)
set_target_properties(multipleinheritance PROPERTIES
set_target_properties(calculatorform_mi PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(multipleinheritance PUBLIC
target_link_libraries(calculatorform_mi PUBLIC
Qt::Core
Qt::Gui
Qt::Widgets
)
install(TARGETS multipleinheritance
install(TARGETS calculatorform_mi
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
@@ -24,7 +24,7 @@
</sizepolicy>
</property>
<property name="windowTitle" >
<string>Calculator Builder</string>
<string>Calculator Form</string>
</property>
<layout class="QGridLayout" >
<property name="objectName" >
@@ -6,6 +6,6 @@ SOURCES = calculatorform.cpp main.cpp
FORMS = calculatorform.ui
#! [0]
target.path = $$[QT_INSTALL_EXAMPLES]/uitools/multipleinheritance
target.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorform_mi
INSTALLS += target
+2 -1
View File
@@ -1,5 +1,6 @@
TEMPLATE = subdirs
SUBDIRS = calculatorform
SUBDIRS = calculatorform \
calculatorform_mi
!contains(CONFIG, static) {
SUBDIRS += calculatorbuilder \

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

@@ -3,8 +3,8 @@
/*!
\example multipleinheritance
\ingroup examples-qtuitools
\title Multiple Inheritance Example
\ingroup examples-designer
\title Calculator Form Example/Multiple Inheritance Example
\brief Using a form created with Qt Designer in an application.
@@ -12,13 +12,13 @@
\l{Qt Designer} in an application by subclassing both QWidget and the user
interface class, which is \c{Ui::CalculatorForm}.
\image multipleinheritance-example.png
\image calculatorform_mi.png
To subclass the \c calculatorform.ui file and ensure that \c qmake
processes it with the \c uic, we have to include \c calculatorform.ui
in the \c .pro file, as shown below:
\snippet multipleinheritance/multipleinheritance.pro 0
\snippet calculatorform_mi/calculatorform_mi.pro 0
When the project is compiled, the \c uic will generate a corresponding
\c ui_calculatorform.h.
@@ -28,12 +28,12 @@
In the \c CalculatorForm definition, we include the \c ui_calculatorform.h
that was generated earlier.
\snippet multipleinheritance/calculatorform.h 0
\snippet calculatorform_mi/calculatorform.h 0
As mentioned earlier, the class is a subclass of both QWidget and
\c{Ui::CalculatorForm}.
\snippet multipleinheritance/calculatorform.h 1
\snippet calculatorform_mi/calculatorform.h 1
Two slots are defined according to the \l{Automatic Connections}
{automatic connection} naming convention required by \c uic. This is
@@ -45,7 +45,7 @@
In the constructor, we call \c setupUi() to load the user interface file.
Note that setupUi is a method of \c Ui::CalculatorForm.
\snippet multipleinheritance/calculatorform.cpp 0
\snippet calculatorform_mi/calculatorform.cpp 0
We include two slots, \c{on_inputSpinBox1_valueChanged()} and
\c{on_inputSpinBox2_valueChanged()}. These slots respond to the
@@ -53,9 +53,9 @@
emit. Whenever there is a change in one spin box's value, we take that
value and add it to whatever value the other spin box has.
\snippet multipleinheritance/calculatorform.cpp 1
\snippet calculatorform_mi/calculatorform.cpp 1
\codeline
\snippet multipleinheritance/calculatorform.cpp 2
\snippet calculatorform_mi/calculatorform.cpp 2
\section1 \c main() Function
@@ -63,7 +63,7 @@
The \c calculator object is displayed by invoking the \l{QWidget::show()}
{show()} function.
\snippet multipleinheritance/main.cpp 0
\snippet calculatorform_mi/main.cpp 0
There are various approaches to include forms into applications. The
Multiple Inheritance approach is just one of them. See
-1
View File
@@ -1,2 +1 @@
qt_internal_add_example(multipleinheritance)
qt_internal_add_example(textfinder)
+1 -3
View File
@@ -1,4 +1,2 @@
TEMPLATE = subdirs
SUBDIRS = multipleinheritance
SUBDIRS += textfinder
SUBDIRS = textfinder
@@ -20,6 +20,7 @@
\li \l{arthurplugin}{Arthur Plugin}
\li \l{calculatorbuilder}{Calculator Builder}\raisedaster
\li \l{calculatorform}{Calculator Form}\raisedaster
\li \l{calculatorform_mi}{Calculator Form Example/Multiple Inheritance Example}\raisedaster
\li \l{customwidgetplugin}{Custom Widget Plugin}\raisedaster
\li \l{taskmenuextension}{Task Menu Extension}\raisedaster
\li \l{containerextension}{Container Extension}\raisedaster
@@ -1931,14 +1931,14 @@ pixmap property in the property editor.
We need to include the header file that \c uic generates from the
\c calculatorform.ui file, as follows:
\snippet ../uitools/multipleinheritance/calculatorform.h 0
\snippet ../designer/calculatorform_mi/calculatorform.h 0
The class is defined in a similar way to the one used in the
\l{The Single Inheritance Approach}{single inheritance approach}, except that
this time we inherit from \e{both} QWidget and \c{Ui::CalculatorForm},
as follows:
\snippet ../uitools/multipleinheritance/calculatorform.h 1
\snippet ../designer/calculatorform_mi/calculatorform.h 1
We inherit \c{Ui::CalculatorForm} privately to ensure that the user
interface objects are private in our subclass. We can also inherit it with
@@ -1949,7 +1949,7 @@ pixmap property in the property editor.
constructor used in the \l{The Single Inheritance Approach}
{single inheritance} example:
\snippet ../uitools/multipleinheritance/calculatorform.cpp 0
\snippet ../designer/calculatorform_mi/calculatorform.cpp 0
In this case, the widgets used in the user interface can be accessed in the
same say as a widget created in code by hand. We no longer require the
@@ -19,7 +19,6 @@
/*
\list
\li \l{Multiple Inheritance Example}\raisedaster
\li \l{Text Finder Example}\raisedaster
\endlist