{"id":3023,"date":"2025-12-10T16:04:07","date_gmt":"2025-12-10T07:04:07","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=3023"},"modified":"2026-01-22T17:10:33","modified_gmt":"2026-01-22T08:10:33","slug":"qt-qml-signal-and-slot","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2025\/12\/10\/qt-qml-signal-and-slot\/","title":{"rendered":"[QT QML]\uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f \/ Signal and Slot"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\uc758 \ucf54\ub4dc\ub294 QT6\uc758 CmakeLists\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.<br>The code below uses CmakeLists from QT6.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb Qt QML\uc5d0\uc11c \uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f\uc744 \ud1b5\ud574\uc11c \uce74\uc6b4\ud130\ub97c \uc99d\uac00\uc2dc\ud0a4\uac70\ub098 \uac10\uc18c\uc2dc\ud0a4\ub294 \ucf54\ub4dc \uc785\ub2c8\ub2e4.<br>This is code to increment or decrement a counter through signals and slots in Qt QML.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f(Signal &amp; Slot)\uc740 \uc6d0\ub798 Qt \ud504\ub808\uc784\uc6cc\ud06c\uc758 \ubfcc\ub9ac\uc778 C++\uc5d0\uc11c \uac1d\uccb4 \uac04\uc758 \ud1b5\uc2e0\uc744 \uc704\ud574 \ud0c4\uc0dd\ud55c \ud575\uc2ec \uac1c\ub150\uc785\ub2c8\ub2e4.<br>Signals and slots are core concepts that were originally born in C++, the root of the Qt framework, for communication between objects.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffbQML\uc740 \uc774 C++ \uc5d4\uc9c4 \uc704\uc5d0\uc11c \ub3cc\uc544\uac00\ub294 \uc5b8\uc5b4\uc774\uae30 \ub54c\ubb38\uc5d0, QML\uacfc C++\uc744 \uc5f0\uacb0\ud558\ub294 \ub2e4\ub9ac \uc5ed\ud560\uc744 \uc2dc\uadf8\ub110\uc774 \uc218\ud589\ud558\uac8c \ub429\ub2c8\ub2e4.<br>Since QML is a language that runs on top of this C++ engine, signals serve as a bridge between QML and C++.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc2dc\uadf8\ub110 \/ Signal<\/p>\n\n\n\n<p>\uc2dc\uadf8\ub110\uc740 \u201c\uc5b4\ub5a4 \uc77c\uc774 \uc77c\uc5b4\ub0ac\ub2e4\u201d\ub294 \uac83\uc744 \uc54c\ub9ac\ub294 \uc774\ubca4\ud2b8\u201d \uc785\ub2c8\ub2e4.<br>A signal is an event that signals that \u201csomething has happened.\u201d<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc2ac\ub86f \/ Slot<\/p>\n\n\n\n<p>\uc2ac\ub86f\uc740 \uc2dc\uadf8\ub110\uc774 \ubc1c\uc0dd\ud588\uc744 \ub54c \uc2e4\ud589\ub418\ub294 \ud568\uc218(\ub3d9\uc791) \uc785\ub2c8\ub2e4.<br>A slot is a function (action) that is executed when a signal is generated.<\/p>\n\n\n\n<p>\u2714\ufe0f\uc2dc\uadf8\ub110\uc744 \ub9cc\ub4e4\uba74 \uc2ac\ub86f\uc740 \uc544\ub798\uc758 \ud615\uc2dd\uc73c\ub85c \ub9cc\ub4e4\uba74 \ub429\ub2c8\ub2e4.<br>When you create a signal, you can create a slot in the format below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>on + \uc2dc\uadf8\ub110\uc774\ub984 \/ Signal Name (\uccab \uae00\uc790 \ub300\ubb38\uc790 \/ First letter is capitalized)<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\uc758 \ucf54\ub4dc\uc5d0\uc11c \uc2dc\uadf8\ub110\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<br>In the code below, the signals are<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>signal incrementRequested()\nsignal decrementRequested()<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\uc758 \ucf54\ub4dc\uc5d0\uc11c \uc704\uc758 \uc2dc\uadf8\ub110\uacfc \uc5f0\uacb0\ub418\ub294 \uc2ac\ub86f\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<br>In the code below, the slots connected to the signals above are<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        onIncrementRequested: {\n            root.count++\n            console.log(\"Count updated:\", root.count)\n        }\n        onDecrementRequested: {\n            if (root.count &gt; 0)  root.count--\n            console.log(\"Count updated:\", root.count)\n        }<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ucf54\ub4dc \/ Code<\/p>\n\n\n\n<p>\u2714\ufe0fMain.qml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import QtQuick\nimport QtQuick.Controls\n\nWindow {\n    width: 640\n    height: 480\n    visible: true\n    title: qsTr(\"Hello World\")\n\n    Rectangle {\n        id: root\n        \/\/width: 300\n        \/\/height: 200\n        anchors.fill: parent\n        color: \"white\"\n\n        \/\/ signal\n        signal incrementRequested()\n        signal decrementRequested()\n        property int count: 0\n\n        Column {\n            anchors.centerIn: parent\n            spacing: 20\n\n            Text {\n                font.pixelSize: 24\n                text: \"Count: \" + root.count\n            }\n            Row{\n                spacing:10\n                Button {\n                    text: \"Increase Count\"\n                    onClicked: { root.incrementRequested() }\n                }\n                Button {\n                    text: \"Decrease Count\"\n                    onClicked: { root.decrementRequested() }\n                }\n\n            }\n\n        }\n        \/\/ \uc790\ub3d9 \uc2ac\ub86f \/ automatic slot\n        onIncrementRequested: {\n            root.count++\n            console.log(\"Count updated:\", root.count)\n        }\n        onDecrementRequested: {\n            if (root.count &gt; 0)  root.count--\n            console.log(\"Count updated:\", root.count)\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc2a4\ud06c\ub9b0 \uc0f7 \/ ScreenShot<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"812\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/12\/signalSlot-1024x812.png\" alt=\"\" class=\"wp-image-4121\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/12\/signalSlot-1024x812.png 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/12\/signalSlot-300x238.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/12\/signalSlot-768x609.png 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/12\/signalSlot-400x317.png 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/12\/signalSlot-800x635.png 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/12\/signalSlot.png 1286w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\uc758 \ucf54\ub4dc\ub294 QT6\uc758 CmakeLists\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.The code below uses CmakeLists from QT6. \ud83d\udc49\ud83c\udffb Qt QML\uc5d0\uc11c \uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f\uc744 \ud1b5\ud574\uc11c \uce74\uc6b4\ud130\ub97c \uc99d\uac00\uc2dc\ud0a4\uac70\ub098 \uac10\uc18c\uc2dc\ud0a4\ub294 \ucf54\ub4dc \uc785\ub2c8\ub2e4.This is code to increment or decrement a counter through signals and slots in Qt QML. \ud83d\udc49\ud83c\udffb\uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f(Signal &amp; Slot)\uc740 \uc6d0\ub798 Qt \ud504\ub808\uc784\uc6cc\ud06c\uc758 \ubfcc\ub9ac\uc778 C++\uc5d0\uc11c \uac1d\uccb4 \uac04\uc758 \ud1b5\uc2e0\uc744 \uc704\ud574 \ud0c4\uc0dd\ud55c \ud575\uc2ec \uac1c\ub150\uc785\ub2c8\ub2e4.Signals and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,1],"tags":[],"class_list":["post-3023","post","type-post","status-publish","format-standard","hentry","category-qt","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/3023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=3023"}],"version-history":[{"count":11,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/3023\/revisions"}],"predecessor-version":[{"id":4125,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/3023\/revisions\/4125"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=3023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=3023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=3023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}