add book
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(1-SyntaxOverview VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app1-SyntaxOverview
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app1-SyntaxOverview
|
||||
URI 1-SyntaxOverview
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app1-SyntaxOverview PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(app1-SyntaxOverview
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app1-SyntaxOverview
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
id: rootId
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("QML Syntax Demo")
|
||||
|
||||
property string textToShow: "hello"
|
||||
|
||||
Row {
|
||||
id: row1
|
||||
anchors.centerIn: parent
|
||||
spacing: 20
|
||||
|
||||
Rectangle {
|
||||
id: redRectId
|
||||
width: 100; height: 100
|
||||
color: "red"
|
||||
radius: 20
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log("Clicked on the red rectangle")
|
||||
textToShow = "red"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: greenRectId
|
||||
width: 100; height: 100
|
||||
color: "green"
|
||||
radius: 20
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log("Clicked on the green rectangle")
|
||||
textToShow = "green"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: blueRectId
|
||||
width: 100; height: 100
|
||||
color: "blue"
|
||||
radius: 20
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log("Clicked on the blue rectangle")
|
||||
textToShow = "blue"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: textRectId
|
||||
width: 100; height: 100
|
||||
color: "dodgerblue"
|
||||
radius: 100
|
||||
Text {
|
||||
id: textId
|
||||
anchors.centerIn: parent
|
||||
text: textToShow
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log("Clicked on the dodgerblue rectangle")
|
||||
textId.text = "broken"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("1-SyntaxOverview", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(2-ExploringDataTypes VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app2-ExploringDataTypes
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app2-ExploringDataTypes
|
||||
URI 2-ExploringDataTypes
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app2-ExploringDataTypes PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(app2-ExploringDataTypes
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app2-ExploringDataTypes
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,101 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("QML Datatypes Demo")
|
||||
|
||||
property string mString: "https://www.learnqt.guide"
|
||||
property int mInt: 45
|
||||
property bool isFemale: true
|
||||
property double mDouble: 77.5
|
||||
property url mUrl: "https://www.learnqt.guide"
|
||||
|
||||
property var aNumber: 100
|
||||
property var aBool: false
|
||||
property var aString: "Hello world!"
|
||||
property var anotherString: String("#FF008800")
|
||||
property var aColor: Qt.rgba(0.2, 0.3, 0.4, 0.5)
|
||||
property var aRect: Qt.rect(10, 10, 10, 10)
|
||||
property var aPoint: Qt.point(10, 10)
|
||||
property var aSize: Qt.size(10, 10)
|
||||
property var aVector3d: Qt.vector3d(100, 100, 100)
|
||||
property var anArray: [1, 2, 3, "four", "five", (function() { return "six"; })]
|
||||
property var anObject: { "foo": 10, "bar": 20 }
|
||||
property var aFunction: (function() { return "one"; })
|
||||
|
||||
property var aFont: Qt.font({family: "Consolas", pointSize: 30, bold: false})
|
||||
property date mDate: "2018-07-19"
|
||||
|
||||
Rectangle {
|
||||
width: 200
|
||||
height: 100 + mInt
|
||||
anchors.centerIn: parent
|
||||
color: aColor
|
||||
|
||||
Text {
|
||||
id: mTextId
|
||||
anchors.centerIn: parent
|
||||
text: mString
|
||||
font.bold: isFemale ? true : false
|
||||
//font: aFont
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
//console.log("The value of mString is: " + mString)
|
||||
print("The value of mString is: " + mString)
|
||||
console.log("The value of mInt is: " + mInt)
|
||||
|
||||
if (isFemale) {
|
||||
console.log("You may wear a dress")
|
||||
} else {
|
||||
console.log("You may wear a suit")
|
||||
}
|
||||
console.log("The value of mDouble is: " + mDouble)
|
||||
console.log("The value of mUrl is: " + mUrl)
|
||||
|
||||
if (mString == mUrl) {
|
||||
console.log("They are the same")
|
||||
} else {
|
||||
console.log("They are NOT the same")
|
||||
}
|
||||
|
||||
console.log("-----------------Playing with var datatype---------------")
|
||||
console.log("The value of aNumber is: " + aNumber)
|
||||
console.log("The value of aBool is: " + aBool)
|
||||
console.log("The value of aString is: " + aString)
|
||||
console.log("The value of anotherString is: " + anotherString)
|
||||
|
||||
console.log("The components of aRect are x:" + aRect.x + ", y:" + aRect.y + ", width:" + aRect.width + ", height:" + aRect.height)
|
||||
|
||||
console.log("The length of the array is: " + anArray.length)
|
||||
|
||||
/*
|
||||
anArray.forEach(function(value,index){
|
||||
if( index ===5){
|
||||
console.log(value())
|
||||
}else
|
||||
{
|
||||
console.log(value)
|
||||
}})
|
||||
*/
|
||||
|
||||
for (var i = 0; i < anArray.length; i++) {
|
||||
if (i === 5) {
|
||||
console.log(anArray[i]())
|
||||
} else {
|
||||
console.log(anArray[i])
|
||||
}
|
||||
}
|
||||
|
||||
console.log("The date is: " + mDate)
|
||||
|
||||
console.log("The function value is: " + aFunction())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("2-ExploringDataTypes", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(3-PropertyBinding VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app3-PropertyBinding
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app3-PropertyBinding
|
||||
URI 3-PropertyBinding
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app3-PropertyBinding PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(app3-PropertyBinding
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app3-PropertyBinding
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("Property Binding Demo")
|
||||
|
||||
Rectangle {
|
||||
id: redRectId
|
||||
width: 50
|
||||
height: width * 1.5
|
||||
color: "red"
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: blueRectId
|
||||
color: "blue"
|
||||
width: 100
|
||||
height: 100
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
redRectId.width = redRectId.width + 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: greenRectId
|
||||
color: "green"
|
||||
width: 100
|
||||
height: 100
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: blueRectId.right
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//redRectId.height = 100 // Doesn't work
|
||||
//redRectId.height = redRectId.width * 1.5 // Doesn't work either
|
||||
|
||||
redRectId.height = Qt.binding(function() {
|
||||
return redRectId.width * 2
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("3-PropertyBinding", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(4-QtGlobalObject VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app4-QtGlobalObject
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app4-QtGlobalObject
|
||||
URI 4-QtGlobalObject
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app4-QtGlobalObject PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(app4-QtGlobalObject
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app4-QtGlobalObject
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("Qt Global Object Demo")
|
||||
|
||||
property var fonts: Qt.fontFamilies()
|
||||
|
||||
Rectangle {
|
||||
width: 300
|
||||
height: 100
|
||||
color: "red"
|
||||
anchors.centerIn: parent
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//Quit the application
|
||||
/*
|
||||
console.log("Quitting the App")
|
||||
Qt.quit()
|
||||
|
||||
//List the available fonts
|
||||
for (var i = 0; i < fonts.length; i++) {
|
||||
console.log("[" + i + "] :" + fonts[i])
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
//Hash a string
|
||||
var mName = "Daniel Gakwaya"
|
||||
var mNameHash = Qt.md5(mName)
|
||||
console.log("The hash of the name is: " + mNameHash)
|
||||
|
||||
//Open url externally
|
||||
Qt.openUrlExternally("https://www.learnqt.guide/udemy-discounted-9/")
|
||||
|
||||
//Open local files with the default program
|
||||
Qt.openUrlExternally("file:///D:/artwork/LearnQt.png")
|
||||
*/
|
||||
|
||||
//Capture platform info
|
||||
console.log("The current platform is: " + Qt.platform.os)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("4-QtGlobalObject", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(5-PropertyHandlers VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app5-PropertyHandlers
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app5-PropertyHandlers
|
||||
URI 5-PropertyHandlers
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app5-PropertyHandlers PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(app5-PropertyHandlers
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app5-PropertyHandlers
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
id: rootId
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("Properties and Handlers Demo")
|
||||
|
||||
property string firstName: "Daniel"
|
||||
onFirstNameChanged: {
|
||||
console.log("The firstname changed to: " + firstName)
|
||||
}
|
||||
|
||||
onTitleChanged: {
|
||||
console.log("The new title is: " + rootId.title)
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: 300
|
||||
height: 100
|
||||
color: "greenyellow"
|
||||
anchors.centerIn: parent
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
firstName = "John"
|
||||
rootId.title = "The sky is blue"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
console.log("The firstname is: " + firstName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("5-PropertyHandlers", "Main");
|
||||
|
||||
return app.exec();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user