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-SignalHandlers 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-SignalHandlers
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app1-SignalHandlers
|
||||
URI 1-SignalHandlers
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app1-SignalHandlers 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-SignalHandlers
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app1-SignalHandlers
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
43
Qt6QMLBeginnersCode/4.SignalsSlots/1-SignalHandlers/Main.qml
Normal file
43
Qt6QMLBeginnersCode/4.SignalsSlots/1-SignalHandlers/Main.qml
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Signal Handlers")
|
||||
|
||||
Rectangle {
|
||||
id: rect
|
||||
width: 150
|
||||
height: 150
|
||||
color: "red"
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
//hoverEnabled: true
|
||||
|
||||
onClicked: {
|
||||
console.log("Clicked on the rect")
|
||||
}
|
||||
|
||||
onDoubleClicked: {
|
||||
console.log("Double clicked on the rect")
|
||||
}
|
||||
|
||||
onEntered: {
|
||||
console.log("You're in!")
|
||||
}
|
||||
|
||||
onExited: {
|
||||
console.log("You're out!")
|
||||
}
|
||||
|
||||
onWheel: function(wheel) {
|
||||
console.log("Wheel: " + wheel.x)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Qt6QMLBeginnersCode/4.SignalsSlots/1-SignalHandlers/main.cpp
Normal file
18
Qt6QMLBeginnersCode/4.SignalsSlots/1-SignalHandlers/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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-SignalHandlers", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(10-MultipleSignalParameters 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(app10-MultipleSignalParameters
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app10-MultipleSignalParameters
|
||||
URI 10-MultipleSignalParameters
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app10-MultipleSignalParameters 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(app10-MultipleSignalParameters
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app10-MultipleSignalParameters
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Multiple Signal Parameters")
|
||||
|
||||
signal info(string last_name,string first_name,int age)
|
||||
|
||||
//Handle all three parameters
|
||||
onInfo: function(l,f,a){
|
||||
print("last name: " + l + ", first name: " + f +", age: "+ a)
|
||||
}
|
||||
|
||||
//Only handle the first two
|
||||
/*
|
||||
onInfo: function(l,f){
|
||||
print("last name: " + l + ", first name: " + f)
|
||||
}
|
||||
*/
|
||||
//Only handle the first one
|
||||
/*
|
||||
onInfo: function(l){
|
||||
print("last name: " +l)
|
||||
}
|
||||
*/
|
||||
//Can only omit trailling parameters. Can't only ignore last name
|
||||
/*
|
||||
onInfo: function(f,a){
|
||||
print(" first name: " + f +", age: "+ a)
|
||||
}
|
||||
*/
|
||||
//Non trailling parameters can be ignored through some hack
|
||||
/*
|
||||
onInfo: function(_,f,a){
|
||||
print(" first name: " + f +", age: "+ a)
|
||||
}
|
||||
*/
|
||||
Rectangle{
|
||||
id: rectId
|
||||
width: 300;
|
||||
height: 300
|
||||
color: "blue"
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
info("John", "Snow", 33)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("10-MultipleSignalParameters", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(2-SignalParameters 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-SignalParameters
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app2-SignalParameters
|
||||
URI 2-SignalParameters
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app2-SignalParameters 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-SignalParameters
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app2-SignalParameters
|
||||
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 {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Signal Parameters")
|
||||
|
||||
Rectangle{
|
||||
id: rect
|
||||
width: 150
|
||||
height: 150
|
||||
color: "red"
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
|
||||
/*
|
||||
onClicked: {
|
||||
//Deprecated
|
||||
console.log(mouse.x)
|
||||
}
|
||||
*/
|
||||
|
||||
//Explicit Javascript function
|
||||
/*
|
||||
onClicked: function(mouse_param){
|
||||
console.log(mouse_param.x)
|
||||
}
|
||||
*/
|
||||
|
||||
//Arrow function
|
||||
onClicked: (mouse_param) => console.log(mouse_param.x)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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-SignalParameters", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(3-PropertChangeSignals 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-PropertChangeSignals
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app3-PropertChangeSignals
|
||||
URI 3-PropertChangeSignals
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app3-PropertChangeSignals 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-PropertChangeSignals
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app3-PropertChangeSignals
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Property change handlers")
|
||||
|
||||
Rectangle {
|
||||
id: rect
|
||||
width: 300
|
||||
height: width
|
||||
color: "dodgerblue"
|
||||
|
||||
property string description: "A rectangle to play with"
|
||||
|
||||
onWidthChanged: function() {
|
||||
console.log("Width changed to: " + rect.width)
|
||||
}
|
||||
|
||||
onHeightChanged: function() {
|
||||
console.log("Height changed to: " + rect.height)
|
||||
}
|
||||
|
||||
onColorChanged: {
|
||||
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
|
||||
}
|
||||
|
||||
onDescriptionChanged: {
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
rect.width = rect.width + 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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-PropertChangeSignals", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(4-Connections 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-Connections
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app4-Connections
|
||||
URI 4-Connections
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app4-Connections 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-Connections
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app4-Connections
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
33
Qt6QMLBeginnersCode/4.SignalsSlots/4-Connections/Main.qml
Normal file
33
Qt6QMLBeginnersCode/4.SignalsSlots/4-Connections/Main.qml
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
import QtQml
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Connections")
|
||||
|
||||
Rectangle{
|
||||
id: rectId
|
||||
width : 200
|
||||
height: 200
|
||||
color: "blue"
|
||||
|
||||
MouseArea{
|
||||
id:mouseAreaId
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target : mouseAreaId
|
||||
function onClicked(){
|
||||
console.log("Hello")
|
||||
}
|
||||
function onDoubleClicked(mouse){
|
||||
console.log("Doubleclicked at: "+mouse.x)
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Qt6QMLBeginnersCode/4.SignalsSlots/4-Connections/main.cpp
Normal file
18
Qt6QMLBeginnersCode/4.SignalsSlots/4-Connections/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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-Connections", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(5-AttachedSignalHandlers 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-AttachedSignalHandlers
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app5-AttachedSignalHandlers
|
||||
URI 5-AttachedSignalHandlers
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app5-AttachedSignalHandlers 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-AttachedSignalHandlers
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app5-AttachedSignalHandlers
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Attached signal handlers")
|
||||
|
||||
Rectangle{
|
||||
width : 200
|
||||
height: 200
|
||||
color : "green"
|
||||
anchors.left: parent.left
|
||||
|
||||
Component.onCompleted: {
|
||||
console.log("Finished setting up the rectangle")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("5-AttachedSignalHandlers", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(6-CustomSignals 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(app6-CustomSignals
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app6-CustomSignals
|
||||
URI 6-CustomSignals
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app6-CustomSignals 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(app6-CustomSignals
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app6-CustomSignals
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
36
Qt6QMLBeginnersCode/4.SignalsSlots/6-CustomSignals/Main.qml
Normal file
36
Qt6QMLBeginnersCode/4.SignalsSlots/6-CustomSignals/Main.qml
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Custom Signals")
|
||||
|
||||
Rectangle{
|
||||
id: rectId
|
||||
width : 300
|
||||
height: 300
|
||||
color: "dodgerblue"
|
||||
|
||||
//Set up the signal
|
||||
signal greet(string message)
|
||||
|
||||
//Once you set up the signal, Qt setup a signal handler automatically
|
||||
onGreet: function(message){
|
||||
console.log("Greeting with message: "+ message)
|
||||
}
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//Fire the signal by just calling it like a function
|
||||
rectId.greet("The sky is blue")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
18
Qt6QMLBeginnersCode/4.SignalsSlots/6-CustomSignals/main.cpp
Normal file
18
Qt6QMLBeginnersCode/4.SignalsSlots/6-CustomSignals/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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("6-CustomSignals", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(7-ConnectSignalToMethod 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(app7-ConnectSignalToMethod
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app7-ConnectSignalToMethod
|
||||
URI 7-ConnectSignalToMethod
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app7-ConnectSignalToMethod 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(app7-ConnectSignalToMethod
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app7-ConnectSignalToMethod
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Connect Signal to Method")
|
||||
|
||||
Rectangle{
|
||||
id: rectId
|
||||
width: 300
|
||||
height: 300
|
||||
color: "dodgerblue"
|
||||
|
||||
//Set up the signal
|
||||
signal greet(string message)
|
||||
|
||||
//WE DON'T WANT TO USE THIS THIS TIME.
|
||||
// Once you set up the signal, Qt setup a signal handler automatically
|
||||
/*
|
||||
onGreet: function(message){
|
||||
console.log("Greeting with message: "+ message)
|
||||
}
|
||||
*/
|
||||
|
||||
//We want to connect, not to a built in signal handler, but to a custom
|
||||
//regular function
|
||||
function respond_your_way(message){
|
||||
console.log("Responding our way; greeting with message: "+ message)
|
||||
}
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//Fire the signal by just calling it like a function
|
||||
rectId.greet("The sky is blue")
|
||||
}
|
||||
}
|
||||
Component.onCompleted: {
|
||||
//Make the connection explicitly
|
||||
rectId.greet.connect(rectId.respond_your_way)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("7-ConnectSignalToMethod", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(8-ConnectingSignalsToSignals 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(app8-ConnectingSignalsToSignals
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app8-ConnectingSignalsToSignals
|
||||
URI 8-ConnectingSignalsToSignals
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app8-ConnectingSignalsToSignals 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(app8-ConnectingSignalsToSignals
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app8-ConnectingSignalsToSignals
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Custom Signals")
|
||||
|
||||
Rectangle{
|
||||
id: rectId
|
||||
width: 300
|
||||
height: 300
|
||||
color: "dodgerblue"
|
||||
anchors.left: parent.left
|
||||
|
||||
//Set up the signal
|
||||
signal greet(string message)
|
||||
signal forward_greeting(string message)
|
||||
|
||||
//We want to connect, not to a build in signal handler, but to a custom
|
||||
//regular function
|
||||
function respond_your_way(message){
|
||||
console.log("Responding our way;Greeting with message: "+message)
|
||||
}
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//Fire the signal by just calling it like a function
|
||||
rectId.greet("The sky is blue")
|
||||
}
|
||||
}
|
||||
Component.onCompleted: {
|
||||
//Connect a signal to another signal
|
||||
rectId.greet.connect(rectId.forward_greeting)
|
||||
//Respond to the final signal
|
||||
rectId.forward_greeting.connect(rectId.respond_your_way)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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("8-ConnectingSignalsToSignals", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(9-DifferentQMLComponentSignals 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(app9-DifferentQMLComponentSignals
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app9-DifferentQMLComponentSignals
|
||||
URI 9-DifferentQMLComponentSignals
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml Notifier.qml Receiver.qml
|
||||
)
|
||||
|
||||
set_target_properties(app9-DifferentQMLComponentSignals 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(app9-DifferentQMLComponentSignals
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app9-DifferentQMLComponentSignals
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("External Components with signals and slots")
|
||||
|
||||
Notifier{
|
||||
id: notifierId
|
||||
rectColor: "yellowgreen"
|
||||
target: receiverId
|
||||
}
|
||||
|
||||
Receiver {
|
||||
id: receiverId
|
||||
rectColor: "dodgerblue"
|
||||
anchors.right: parent.right
|
||||
}
|
||||
|
||||
/*
|
||||
Component.onCompleted: {
|
||||
notifierId.notify.connect(receiverId.receiveInfo)//Connect signal to slot
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Item {
|
||||
|
||||
//Could have used an alias for rectColor here, but I just want you
|
||||
//to see that you can also do it this way, and rely on the property handler
|
||||
// to save the new color when applied.
|
||||
|
||||
|
||||
width: notifierRectId.width
|
||||
height: notifierRectId.height
|
||||
property int count: 0
|
||||
signal notify( string count)//Declare signal
|
||||
|
||||
|
||||
property Receiver target: null
|
||||
onTargetChanged: {
|
||||
notify.connect(target.receiveInfo)
|
||||
}
|
||||
|
||||
property color rectColor: "black"
|
||||
onRectColorChanged: {
|
||||
notifierRectId.color = rectColor
|
||||
}
|
||||
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: notifierRectId
|
||||
width: 200
|
||||
height: 200
|
||||
color: "red"
|
||||
|
||||
|
||||
Text {
|
||||
id: displayTextId
|
||||
anchors.centerIn: parent
|
||||
font.pointSize: 20
|
||||
text: count
|
||||
}
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
count++
|
||||
notify(count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Item {
|
||||
|
||||
property alias rectColor: receiverRectId.color
|
||||
width: receiverRectId.width
|
||||
height: receiverRectId.height
|
||||
|
||||
|
||||
function receiveInfo( count){
|
||||
receiverDisplayTextId.text = count
|
||||
console.log("Receiver received number: "+ count)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: receiverRectId
|
||||
width: 200
|
||||
height: 200
|
||||
color: "blue"
|
||||
|
||||
|
||||
Text {
|
||||
id: receiverDisplayTextId
|
||||
anchors.centerIn: parent
|
||||
font.pointSize: 20
|
||||
text: "0"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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("9-DifferentQMLComponentSignals", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user