Fix CMakeLists.txts of chattutorial

- Run pro2cmake.py on each .pro and did some manual adjustments.
- Rename directories to simplify resource paths, URIs, etc.
- Rename executables to ensure they're distinguishable from other
  targets in Creator's locator.
- Duplicate images into each example due to issues with resources.
- Now that we use qt_add_qml_module, the qtquickcontrols2.conf
  file will no longer be at the resource root, so specify it
  separately with qt6_add_resources.
- Update qmake files.
- Fix documentation.

Task-number: QTBUG-98130
Pick-to: 6.2
Change-Id: I210ef2cbcd45dd7f4df881332174bff1b18c5be7
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Mitch Curtis 2021-11-08 12:02:30 +01:00
parent de6c7aa734
commit 5e8e12b342
110 changed files with 517 additions and 524 deletions

View File

@ -1,10 +1,10 @@
# Generated from chattutorial.pro.
add_subdirectory(chapter1-settingup)
add_subdirectory(chapter2-lists)
add_subdirectory(chapter3-navigation)
add_subdirectory(chapter1)
add_subdirectory(chapter2)
add_subdirectory(chapter3)
if (TARGET Qt::Sql)
add_subdirectory(chapter4-models)
add_subdirectory(chapter5-styling)
add_subdirectory(chapter4)
add_subdirectory(chapter5)
endif()

View File

@ -1,54 +0,0 @@
# Generated from chapter1-settingup.pro.
cmake_minimum_required(VERSION 3.16)
project(chapter1-settingup LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter1-settingup")
find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Qml)
find_package(Qt6 COMPONENTS Quick)
qt_add_executable(chapter1-settingup
main.cpp
)
set_target_properties(chapter1-settingup PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(chapter1-settingup PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
)
# Resources:
set(qml_resource_files
"main.qml"
)
qt6_add_resources(chapter1-settingup "qml"
PREFIX
"/"
FILES
${qml_resource_files}
)
install(TARGETS chapter1-settingup
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -1,11 +0,0 @@
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter1-settingup
INSTALLS += target

View File

@ -1,6 +0,0 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.16)
project(chapter1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter1")
find_package(Qt6 COMPONENTS Core Gui Qml Quick)
qt_add_executable(chattutorial-chapter1 WIN32 MACOSX_BUNDLE
main.cpp
)
target_link_libraries(chattutorial-chapter1 PRIVATE
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
)
qt_add_qml_module(chattutorial-chapter1
URI chapter1
VERSION 1.0
QML_FILES
"main.qml"
)
qt6_add_resources(chattutorial-chapter1 "conf"
PREFIX
"/"
FILES
"qtquickcontrols2.conf"
)
install(TARGETS chattutorial-chapter1
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -5,8 +5,9 @@ CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc \
../shared/shared.qrc
RESOURCES += \
main.qml \
qtquickcontrols2.conf
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter2-lists
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter1
INSTALLS += target

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
engine.load(QUrl(QStringLiteral("qrc:/chapter1/main.qml")));
return app.exec();
}

View File

@ -0,0 +1,2 @@
[Controls]
Style=Basic

View File

@ -1,77 +0,0 @@
# Generated from chapter2-lists.pro.
cmake_minimum_required(VERSION 3.16)
project(chapter2-lists LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter2-lists")
find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Qml)
find_package(Qt6 COMPONENTS Quick)
qt_add_executable(chapter2-lists
main.cpp
)
set_target_properties(chapter2-lists PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(chapter2-lists PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
)
# Resources:
set(qml_resource_files
"main.qml"
)
qt6_add_resources(chapter2-lists "qml"
PREFIX
"/"
FILES
${qml_resource_files}
)
set(shared_resource_files
"../shared/Albert_Einstein.png"
"../shared/Albert_Einstein@2x.png"
"../shared/Albert_Einstein@3x.png"
"../shared/Albert_Einstein@4x.png"
"../shared/Ernest_Hemingway.png"
"../shared/Ernest_Hemingway@2x.png"
"../shared/Ernest_Hemingway@3x.png"
"../shared/Ernest_Hemingway@4x.png"
"../shared/Hans_Gude.png"
"../shared/Hans_Gude@2x.png"
"../shared/Hans_Gude@3x.png"
"../shared/Hans_Gude@4x.png"
)
qt6_add_resources(chapter2-lists "shared"
PREFIX
"/"
BASE
"../shared"
FILES
${shared_resource_files}
)
install(TARGETS chapter2-lists
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -1,6 +0,0 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.16)
project(chapter2 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter2")
find_package(Qt6 COMPONENTS Core Gui Qml Quick)
qt_add_executable(chattutorial-chapter2 WIN32 MACOSX_BUNDLE
main.cpp
)
target_link_libraries(chattutorial-chapter2 PRIVATE
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
)
qt_add_qml_module(chattutorial-chapter2
URI chapter2
VERSION 1.0
QML_FILES
"main.qml"
RESOURCES
"images/Albert_Einstein.png"
"images/Albert_Einstein@2x.png"
"images/Albert_Einstein@3x.png"
"images/Albert_Einstein@4x.png"
"images/Ernest_Hemingway.png"
"images/Ernest_Hemingway@2x.png"
"images/Ernest_Hemingway@3x.png"
"images/Ernest_Hemingway@4x.png"
"images/Hans_Gude.png"
"images/Hans_Gude@2x.png"
"images/Hans_Gude@3x.png"
"images/Hans_Gude@4x.png"
)
qt6_add_resources(chattutorial-chapter2 "conf"
PREFIX
"/"
FILES
"qtquickcontrols2.conf"
)
install(TARGETS chattutorial-chapter2
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -0,0 +1,25 @@
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += \
images/Albert_Einstein.png \
images/Albert_Einstein@2x.png \
images/Albert_Einstein@3x.png \
images/Albert_Einstein@4x.png \
images/Ernest_Hemingway.png \
images/Ernest_Hemingway@2x.png \
images/Ernest_Hemingway@3x.png \
images/Ernest_Hemingway@4x.png \
images/Hans_Gude.png \
images/Hans_Gude@2x.png \
images/Hans_Gude@3x.png \
images/Hans_Gude@4x.png \
main.qml \
qtquickcontrols2.conf
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter2
INSTALLS += target

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
engine.load(QUrl(QStringLiteral("qrc:/chapter2/main.qml")));
return app.exec();
}

View File

@ -83,7 +83,7 @@ ApplicationWindow {
Image {
id: avatar
source: "qrc:/" + modelData.replace(" ", "_") + ".png"
source: "images/" + modelData.replace(" ", "_") + ".png"
}
}
}

View File

@ -0,0 +1,2 @@
[Controls]
Style=Basic

View File

@ -1,79 +0,0 @@
# Generated from chapter3-navigation.pro.
cmake_minimum_required(VERSION 3.16)
project(chapter3-navigation LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter3-navigation")
find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Qml)
find_package(Qt6 COMPONENTS Quick)
qt_add_executable(chapter3-navigation
main.cpp
)
set_target_properties(chapter3-navigation PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(chapter3-navigation PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
)
# Resources:
set(qml_resource_files
"ContactPage.qml"
"ConversationPage.qml"
"main.qml"
)
qt6_add_resources(chapter3-navigation "qml"
PREFIX
"/"
FILES
${qml_resource_files}
)
set(shared_resource_files
"../shared/Albert_Einstein.png"
"../shared/Albert_Einstein@2x.png"
"../shared/Albert_Einstein@3x.png"
"../shared/Albert_Einstein@4x.png"
"../shared/Ernest_Hemingway.png"
"../shared/Ernest_Hemingway@2x.png"
"../shared/Ernest_Hemingway@3x.png"
"../shared/Ernest_Hemingway@4x.png"
"../shared/Hans_Gude.png"
"../shared/Hans_Gude@2x.png"
"../shared/Hans_Gude@3x.png"
"../shared/Hans_Gude@4x.png"
)
qt6_add_resources(chapter3-navigation "shared"
PREFIX
"/"
BASE
"../shared"
FILES
${shared_resource_files}
)
install(TARGETS chapter3-navigation
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -1,12 +0,0 @@
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc \
../shared/shared.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter3-navigation
INSTALLS += target

View File

@ -1,7 +0,0 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>ContactPage.qml</file>
<file>ConversationPage.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.16)
project(chapter3 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter3")
find_package(Qt6 COMPONENTS Core Gui Qml Quick)
qt_add_executable(chattutorial-chapter3 WIN32 MACOSX_BUNDLE
main.cpp
)
target_link_libraries(chattutorial-chapter3 PRIVATE
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
)
# Resources:
qt_add_qml_module(chattutorial-chapter3
URI chapter3
VERSION 1.0
QML_FILES
"ContactPage.qml"
"ConversationPage.qml"
"main.qml"
RESOURCES
"images/Albert_Einstein.png"
"images/Albert_Einstein@2x.png"
"images/Albert_Einstein@3x.png"
"images/Albert_Einstein@4x.png"
"images/Ernest_Hemingway.png"
"images/Ernest_Hemingway@2x.png"
"images/Ernest_Hemingway@3x.png"
"images/Ernest_Hemingway@4x.png"
"images/Hans_Gude.png"
"images/Hans_Gude@2x.png"
"images/Hans_Gude@3x.png"
"images/Hans_Gude@4x.png"
)
qt6_add_resources(chattutorial-chapter3 "conf"
PREFIX
"/"
FILES
"qtquickcontrols2.conf"
)
install(TARGETS chattutorial-chapter3
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -76,11 +76,11 @@ Page {
width: listView.width - listView.leftMargin - listView.rightMargin
height: avatar.implicitHeight
leftPadding: avatar.implicitWidth + 32
onClicked: root.StackView.view.push("qrc:/ConversationPage.qml", { inConversationWith: modelData })
onClicked: root.StackView.view.push("ConversationPage.qml", { inConversationWith: modelData })
Image {
id: avatar
source: "qrc:/" + modelData.replace(" ", "_") + ".png"
source: "images/" + modelData.replace(" ", "_") + ".png"
}
}
}

View File

@ -0,0 +1,27 @@
TEMPLATE = app
QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += \
ContactPage.qml \
ConversationPage.qml \
images/Albert_Einstein.png \
images/Albert_Einstein@2x.png \
images/Albert_Einstein@3x.png \
images/Albert_Einstein@4x.png \
images/Ernest_Hemingway.png \
images/Ernest_Hemingway@2x.png \
images/Ernest_Hemingway@3x.png \
images/Ernest_Hemingway@4x.png \
images/Hans_Gude.png \
images/Hans_Gude@2x.png \
images/Hans_Gude@3x.png \
images/Hans_Gude@4x.png \
main.qml \
qtquickcontrols2.conf
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter3
INSTALLS += target

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -0,0 +1,16 @@
<RCC>
<qresource prefix="/">
<file>Albert_Einstein.png</file>
<file>Albert_Einstein@2x.png</file>
<file>Albert_Einstein@3x.png</file>
<file>Albert_Einstein@4x.png</file>
<file>Ernest_Hemingway.png</file>
<file>Ernest_Hemingway@2x.png</file>
<file>Ernest_Hemingway@3x.png</file>
<file>Ernest_Hemingway@4x.png</file>
<file>Hans_Gude.png</file>
<file>Hans_Gude@2x.png</file>
<file>Hans_Gude@3x.png</file>
<file>Hans_Gude@4x.png</file>
</qresource>
</RCC>

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
engine.load(QUrl(QStringLiteral("qrc:/chapter3/main.qml")));
return app.exec();
}

View File

@ -0,0 +1,2 @@
[Controls]
Style=Basic

View File

@ -1,83 +0,0 @@
# Generated from chapter4-models.pro.
cmake_minimum_required(VERSION 3.16)
project(chapter4-models LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter4-models")
find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Qml)
find_package(Qt6 COMPONENTS Quick)
find_package(Qt6 COMPONENTS Sql)
qt_add_executable(chapter4-models
main.cpp
sqlcontactmodel.cpp sqlcontactmodel.h
sqlconversationmodel.cpp sqlconversationmodel.h
)
set_target_properties(chapter4-models PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(chapter4-models PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
Qt::Sql
)
# Resources:
set(qml_resource_files
"ContactPage.qml"
"ConversationPage.qml"
"main.qml"
)
qt6_add_resources(chapter4-models "qml"
PREFIX
"/"
FILES
${qml_resource_files}
)
set(shared_resource_files
"../shared/Albert_Einstein.png"
"../shared/Albert_Einstein@2x.png"
"../shared/Albert_Einstein@3x.png"
"../shared/Albert_Einstein@4x.png"
"../shared/Ernest_Hemingway.png"
"../shared/Ernest_Hemingway@2x.png"
"../shared/Ernest_Hemingway@3x.png"
"../shared/Ernest_Hemingway@4x.png"
"../shared/Hans_Gude.png"
"../shared/Hans_Gude@2x.png"
"../shared/Hans_Gude@3x.png"
"../shared/Hans_Gude@4x.png"
)
qt6_add_resources(chapter4-models "shared"
PREFIX
"/"
BASE
"../shared"
FILES
${shared_resource_files}
)
install(TARGETS chapter4-models
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -1,18 +0,0 @@
TEMPLATE = app
QT += qml quick sql
CONFIG += c++11
HEADERS += sqlcontactmodel.h \
sqlconversationmodel.h
SOURCES += main.cpp \
sqlcontactmodel.cpp \
sqlconversationmodel.cpp
RESOURCES += \
qml.qrc \
../shared/shared.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter4-models
INSTALLS += target

View File

@ -1,7 +0,0 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>ContactPage.qml</file>
<file>ConversationPage.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.16)
project(chapter4 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter4")
find_package(Qt6 COMPONENTS Core Gui Qml Quick Sql)
qt_add_executable(chattutorial-chapter4 WIN32 MACOSX_BUNDLE
main.cpp
sqlcontactmodel.cpp sqlcontactmodel.h
sqlconversationmodel.cpp sqlconversationmodel.h
)
target_link_libraries(chattutorial-chapter4 PRIVATE
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
Qt::Sql
)
# Resources:
qt_add_qml_module(chattutorial-chapter4
URI chapter4
VERSION 1.0
QML_FILES
"ContactPage.qml"
"ConversationPage.qml"
"main.qml"
RESOURCES
"images/Albert_Einstein.png"
"images/Albert_Einstein@2x.png"
"images/Albert_Einstein@3x.png"
"images/Albert_Einstein@4x.png"
"images/Ernest_Hemingway.png"
"images/Ernest_Hemingway@2x.png"
"images/Ernest_Hemingway@3x.png"
"images/Ernest_Hemingway@4x.png"
"images/Hans_Gude.png"
"images/Hans_Gude@2x.png"
"images/Hans_Gude@3x.png"
"images/Hans_Gude@4x.png"
)
qt6_add_resources(chattutorial-chapter4 "conf"
PREFIX
"/"
FILES
"qtquickcontrols2.conf"
)
install(TARGETS chattutorial-chapter4
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -78,11 +78,11 @@ Page {
width: listView.width - listView.leftMargin - listView.rightMargin
height: avatar.implicitHeight
leftPadding: avatar.implicitWidth + 32
onClicked: root.StackView.view.push("qrc:/ConversationPage.qml", { inConversationWith: model.display })
onClicked: root.StackView.view.push("ConversationPage.qml", { inConversationWith: model.display })
Image {
id: avatar
source: "qrc:/" + model.display.replace(" ", "_") + ".png"
source: "images/" + model.display.replace(" ", "_") + ".png"
}
}
}

View File

@ -104,7 +104,7 @@ Page {
Image {
id: avatar
source: !sentByMe ? "qrc:/" + model.author.replace(" ", "_") + ".png" : ""
source: !sentByMe ? "images/" + model.author.replace(" ", "_") + ".png" : ""
}
Rectangle {

View File

@ -0,0 +1,32 @@
TEMPLATE = app
QT += qml quick sql
CONFIG += c++11
HEADERS += sqlcontactmodel.h \
sqlconversationmodel.h
SOURCES += main.cpp \
sqlcontactmodel.cpp \
sqlconversationmodel.cpp
RESOURCES += \
ContactPage.qml \
ConversationPage.qml \
images/Albert_Einstein.png \
images/Albert_Einstein@2x.png \
images/Albert_Einstein@3x.png \
images/Albert_Einstein@4x.png \
images/Ernest_Hemingway.png \
images/Ernest_Hemingway@2x.png \
images/Ernest_Hemingway@3x.png \
images/Ernest_Hemingway@4x.png \
images/Hans_Gude.png \
images/Hans_Gude@2x.png \
images/Hans_Gude@3x.png \
images/Hans_Gude@4x.png \
main.qml \
qtquickcontrols2.conf
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter4
INSTALLS += target

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -0,0 +1,16 @@
<RCC>
<qresource prefix="/">
<file>Albert_Einstein.png</file>
<file>Albert_Einstein@2x.png</file>
<file>Albert_Einstein@3x.png</file>
<file>Albert_Einstein@4x.png</file>
<file>Ernest_Hemingway.png</file>
<file>Ernest_Hemingway@2x.png</file>
<file>Ernest_Hemingway@3x.png</file>
<file>Ernest_Hemingway@4x.png</file>
<file>Hans_Gude.png</file>
<file>Hans_Gude@2x.png</file>
<file>Hans_Gude@3x.png</file>
<file>Hans_Gude@4x.png</file>
</qresource>
</RCC>

View File

@ -90,7 +90,7 @@ int main(int argc, char *argv[])
connectToDatabase();
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
engine.load(QUrl(QStringLiteral("qrc:/chapter4/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;

View File

@ -0,0 +1,2 @@
[Controls]
Style=Basic

View File

@ -1,86 +0,0 @@
# Generated from chapter5-styling.pro.
cmake_minimum_required(VERSION 3.16)
project(chapter5-styling LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter5-styling")
find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Qml)
find_package(Qt6 COMPONENTS Quick)
find_package(Qt6 COMPONENTS Sql)
qt_add_executable(chapter5-styling
main.cpp
sqlcontactmodel.cpp sqlcontactmodel.h
sqlconversationmodel.cpp sqlconversationmodel.h
)
set_target_properties(chapter5-styling PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(chapter5-styling PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
Qt::Sql
)
# Resources:
set(qml_resource_files
"+Material/ChatToolBar.qml"
"ChatToolBar.qml"
"ContactPage.qml"
"ConversationPage.qml"
"main.qml"
"qtquickcontrols2.conf"
)
qt6_add_resources(chapter5-styling "qml"
PREFIX
"/"
FILES
${qml_resource_files}
)
set(shared_resource_files
"../shared/Albert_Einstein.png"
"../shared/Albert_Einstein@2x.png"
"../shared/Albert_Einstein@3x.png"
"../shared/Albert_Einstein@4x.png"
"../shared/Ernest_Hemingway.png"
"../shared/Ernest_Hemingway@2x.png"
"../shared/Ernest_Hemingway@3x.png"
"../shared/Ernest_Hemingway@4x.png"
"../shared/Hans_Gude.png"
"../shared/Hans_Gude@2x.png"
"../shared/Hans_Gude@3x.png"
"../shared/Hans_Gude@4x.png"
)
qt6_add_resources(chapter5-styling "shared"
PREFIX
"/"
BASE
"../shared"
FILES
${shared_resource_files}
)
install(TARGETS chapter5-styling
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -1,18 +0,0 @@
TEMPLATE = app
QT += qml quick sql
CONFIG += c++11
HEADERS += sqlcontactmodel.h \
sqlconversationmodel.h
SOURCES += main.cpp \
sqlcontactmodel.cpp \
sqlconversationmodel.cpp
RESOURCES += \
qml.qrc \
../shared/shared.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter5-styling
INSTALLS += target

View File

@ -1,10 +0,0 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>ContactPage.qml</file>
<file>ConversationPage.qml</file>
<file>qtquickcontrols2.conf</file>
<file>ChatToolBar.qml</file>
<file>+Material/ChatToolBar.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,65 @@
cmake_minimum_required(VERSION 3.16)
project(chapter5 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/chattutorial/chapter5")
find_package(Qt6 COMPONENTS Core Gui Qml Quick Sql)
qt_add_executable(chattutorial-chapter5 WIN32 MACOSX_BUNDLE
main.cpp
sqlcontactmodel.cpp sqlcontactmodel.h
sqlconversationmodel.cpp sqlconversationmodel.h
)
target_link_libraries(chattutorial-chapter5 PRIVATE
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
Qt::Sql
)
# Resources:
qt_add_qml_module(chattutorial-chapter5
URI chapter5
VERSION 1.0
QML_FILES
"+Material/ChatToolBar.qml"
"ChatToolBar.qml"
"ContactPage.qml"
"ConversationPage.qml"
"main.qml"
RESOURCES
"images/Albert_Einstein.png"
"images/Albert_Einstein@2x.png"
"images/Albert_Einstein@3x.png"
"images/Albert_Einstein@4x.png"
"images/Ernest_Hemingway.png"
"images/Ernest_Hemingway@2x.png"
"images/Ernest_Hemingway@3x.png"
"images/Ernest_Hemingway@4x.png"
"images/Hans_Gude.png"
"images/Hans_Gude@2x.png"
"images/Hans_Gude@3x.png"
"images/Hans_Gude@4x.png"
)
qt6_add_resources(chattutorial-chapter5 "conf"
PREFIX
"/"
FILES
"qtquickcontrols2.conf"
)
install(TARGETS chattutorial-chapter5
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -78,11 +78,11 @@ Page {
width: listView.width - listView.leftMargin - listView.rightMargin
height: avatar.implicitHeight
leftPadding: avatar.implicitWidth + 32
onClicked: root.StackView.view.push("qrc:/ConversationPage.qml", { inConversationWith: model.display })
onClicked: root.StackView.view.push("ConversationPage.qml", { inConversationWith: model.display })
Image {
id: avatar
source: "qrc:/" + model.display.replace(" ", "_") + ".png"
source: "images/" + model.display.replace(" ", "_") + ".png"
}
}
}

View File

@ -104,7 +104,7 @@ Page {
Image {
id: avatar
source: !sentByMe ? "qrc:/" + model.author.replace(" ", "_") + ".png" : ""
source: !sentByMe ? "images/" + model.author.replace(" ", "_") + ".png" : ""
}
Rectangle {

View File

@ -0,0 +1,34 @@
TEMPLATE = app
QT += qml quick sql
CONFIG += c++11
HEADERS += sqlcontactmodel.h \
sqlconversationmodel.h
SOURCES += main.cpp \
sqlcontactmodel.cpp \
sqlconversationmodel.cpp
RESOURCES += \
+Material/ChatToolBar.qml \
ChatToolBar.qml \
ContactPage.qml \
ConversationPage.qml \
images/Albert_Einstein.png \
images/Albert_Einstein@2x.png \
images/Albert_Einstein@3x.png \
images/Albert_Einstein@4x.png \
images/Ernest_Hemingway.png \
images/Ernest_Hemingway@2x.png \
images/Ernest_Hemingway@3x.png \
images/Ernest_Hemingway@4x.png \
images/Hans_Gude.png \
images/Hans_Gude@2x.png \
images/Hans_Gude@3x.png \
images/Hans_Gude@4x.png \
main.qml \
qtquickcontrols2.conf
target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter5
INSTALLS += target

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Some files were not shown because too many files have changed in this diff Show More