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(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