{"id":2131,"date":"2025-10-08T16:03:39","date_gmt":"2025-10-08T07:03:39","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=2131"},"modified":"2025-10-09T09:24:59","modified_gmt":"2025-10-09T00:24:59","slug":"qtexample1-signals-and-slots","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2025\/10\/08\/qtexample1-signals-and-slots\/","title":{"rendered":"[QT]example1-\uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f \/ Signals and Slots"},"content":{"rendered":"\n<p><strong>1.\ub514\uc790\uc778\ub9cc\ub4e4\uae30<\/strong> \/ Create a design<br>&#8212; mainwindow.ui\ub97c \ub354\ube14\ud074\ub9ad\ud558\uba74 \ub514\uc790\uc778\uc744 \ub9cc\ub4e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can create a design by double-clicking mainwindow.ui.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"465\" height=\"645\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-1.png\" alt=\"\" class=\"wp-image-2141\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-1.png 465w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-1-216x300.png 216w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/figure>\n\n\n\n<p>&#8212; \uc88c\uce21\uc758 Widget Box\ub97c \uc774\uc6a9\ud574\uc11c \ub2e4\uc74c\uacfc \uac19\uc774 \ud654\uba74\uc744 \uad6c\uc131\ud569\ub2c8\ub2e4.<br>&#8212; objectName\uc740 \uc6b0\uce21\uc758 \ud328\ub110\uc5d0\uc11c \ubc14\uafc0 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br><br>1)\ub808\uc774\uc544\uc6c3:Vertical Layout<\/p>\n\n\n\n<p>2) \ubc84\ud2bc : Push Button<br>==&gt; objectName : pushButton<\/p>\n\n\n\n<p>3)\uc785\ub825 : PlainText Edit<br>==&gt; \uc785\ub8251 : objectName : plainTextEdit<br>==&gt; \uc785\ub8252 : objectName : plainTextEdit<\/p>\n\n\n\n<p>4)\uac12 \ucd9c\ub825 : Label<br>==&gt; objectName : label<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"677\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-2-1024x677.png\" alt=\"\" class=\"wp-image-2142\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-2-1024x677.png 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-2-300x198.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-2-768x508.png 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2025\/10\/example1-2.png 1133w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"mainwindow.h\"\n#include &lt;QApplication&gt;\n\nint main(int argc, char *argv&#91;])\n{\n    \/\/ \ud504\ub85c\uadf8\ub7a8 \uc2dc\uc791\uc810 \ucd5c\uc18c\ud55c\uc758 \ucf54\ub529\n    \/\/ Program starting point with minimal coding\n\n    QApplication a(argc, argv);\n    MainWindow w;\n    w.show();\n    return a.exec();\n}\n<\/code><\/pre>\n\n\n\n<p>mainwindow.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"mainwindow.h\"\n#include \".\/ui_mainwindow.h\"\n\n\/\/ mainWindow\ub294 UI + \uc5f0\uacb0 \uc5ed\ud560 \ub2f4\ub2f9\n\/\/ mainWindow is responsible for UI + connection.\n\nMainWindow::MainWindow(QWidget *parent)\n    : QMainWindow(parent)\n    , ui(new Ui::MainWindow)\n{\n    \/\/ ui\ucd08\uae30\ud654&#91;\uae30\ubcf8\ucf54\ub4dc](Qt Designer\uc5d0\uc11c \ub9cc\ub4e0 UI \ubd88\ub7ec\uc624\uae30)\n    \/\/ UI initialization &#91;basic code] (loading UI created in Qt Designer)\n    ui->setupUi(this);\n\n    \/\/\n    \/\/ \uc0dd\uc131\uc790 \uc548\uc5d0\uc11c \ud55c \ubc88\ub9cc \uc124\uc815,\ud0ed\ud0a4 \ub204\ub974\uba74 \ub2e4\uc74c \ud14d\uc2a4\ud2b8\ub85c \uc774\ub3d9\n    \/\/ Set once in constructor, press tab key to move to next text\n    \/\/\n    \/\/ \uc5ec\uae30\uc11c\ubd80\ud130 \ucf54\ub529\uc2dc\uc791 \/ Start coding from here -->\n    \/\/\n\n    ui->plainTextEdit->setTabChangesFocus(true);\n    ui->plainTextEdit2->setTabChangesFocus(true);\n\n\n    \/\/ \ubc84\ud2bc \ud074\ub9ad \uc2dc \uc785\ub825\uac12\uc744 \ub77c\ubca8\uc5d0 \ucd9c\ub825\n    \/\/ \rWhen a button is clicked, the input value is output to the label.3\n\n    connect(ui->pushButton, &amp;QPushButton::clicked, this, &#91;=](){\n\n        \/\/ \ub450 \uac1c\uc758 QPlainTextEdit\uc5d0\uc11c \ud14d\uc2a4\ud2b8 \uac00\uc838\uc624\uae30\n        \/\/ Get text from two QPlainTextEdits\n\n        QString text1 = ui->plainTextEdit->toPlainText();\n        QString text2 = ui->plainTextEdit2->toPlainText();\n\n        \/\/ \ubb38\uc790\uc5f4 \uc5f0\uacb0\n        \/\/ string concatenation\n        QString combined = text1 + text2;\n\n        \/\/ label\uc5d0 \ucd9c\ub825\n        \/\/ Print on label\n        ui->label->setText(combined);\n    });\n\n    \/\/&lt;-- \uc5ec\uae30\uae4c\uc9c0 \ucf54\ub529 \/ Coding up to here\n\n\n}\n\nMainWindow::~MainWindow()\n{\n    delete ui;\n}<\/code><\/pre>\n\n\n\n<p><strong>1.\ucf54\ub4dc \uc124\uba85 \/ Code Description<\/strong><br>\u2014 \ud14d\uc2a4\ud2b8 \uc785\ub825 2\uac1c\uc5d0\uc11c \ubc1b\uc740 \uac12\uc744 \ubc84\ud2bc \ub204\ub97c \uacbd\uc6b0 \ub77c\ubca8\uc5d0 \ucd9c\ub825\ud558\ub294 \uc608\uc81c \uc785\ub2c8\ub2e4.<br>This is an example of printing the values \u200b\u200breceived from two text inputs to a label when a button is pressed.<\/p>\n\n\n\n<p>1).\uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f \/ SIgnal and Slots<br>&#8212; \uad75\uc740 \uae00\uc790 \ubd80\ubd84\uc774 \uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f\uc744 \uc0ac\uc6a9\ud558\ub294 \uad6c\uc870\uc785\ub2c8\ub2e4.<br>The bold part is the structure that uses signals and slots.<br>&#8211;<strong>&#8211; <\/strong><code><strong>&amp;QPushButton::clicked<\/strong><\/code> ==> \uc774 \ubd80\ubd84\uc740 \uc2dc\uadf8\ub110, \uc774\ubca4\ud2b8 \ubc1c\uc0dd\ud558\ub294 \ubd80\ubd84 \uc785\ub2c8\ub2e4.<br>&amp;QPushButton::clicked ==> This part is where the signal and event occur.<br>&#8212; <strong>[=](){} <\/strong>==> \uc774  Lambda\ubd80\ubd84\uc774 \uc2e4\ud589\ub420 \ud568\uc218\uac00 \ud638\ucd9c \ub418\ub294 \ubd80\ubd84 \uc785\ub2c8\ub2e4.<br>[=](){} ==> This Lambda part is where the function to be executed is called.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>connect(ui-&gt;pushButton, &amp;QPushButton::clicked, this, &#91;=](){<\/strong>\n\n        \/\/ \ub450 \uac1c\uc758 QPlainTextEdit\uc5d0\uc11c \ud14d\uc2a4\ud2b8 \uac00\uc838\uc624\uae30\n        QString text1 = ui-&gt;plainTextEdit-&gt;toPlainText();\n        QString text2 = ui-&gt;plainTextEdit2-&gt;toPlainText();\n\n        \/\/ \ubb38\uc790\uc5f4 \uc5f0\uacb0\n        QString combined = text1 + text2;\n\n        \/\/ label\uc5d0 \ucd9c\ub825\n        ui-&gt;label-&gt;setText(combined);\n <strong>   });<\/strong><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Qt<\/th><th>C++ \uad6c\uc870<\/th><\/tr><\/thead><tbody><tr><td><code>connect(button, &amp;QPushButton::clicked, this, [](){ ... });<\/code><\/td><td>\ubc84\ud2bc \ud074\ub9ad \u2192 \uba64\ubc84 \ud568\uc218 \ud3ec\uc778\ud130 &amp; Lambda \ud638\ucd9c<br>Click button \u2192 Call member function pointer &amp; Lambda<\/td><\/tr><tr><td><code>clicked<\/code> \u2192 \uc2dc\uadf8\ub110\/Signal<\/td><td>\uba64\ubc84 \ud568\uc218 \ud3ec\uc778\ud130<br>member function pointer<\/td><\/tr><tr><td>Lambda \u2192 \uc2ac\ub86f\/Slot<\/td><td>C++ \ud568\uc218 \ud638\ucd9c<br>C++ function call<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">\uc2dc\uadf8\ub110\uacfc \uc2ac\ub86f \/ Singnal and Slot<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1.\ub514\uc790\uc778\ub9cc\ub4e4\uae30 \/ Create a design&#8212; mainwindow.ui\ub97c \ub354\ube14\ud074\ub9ad\ud558\uba74 \ub514\uc790\uc778\uc744 \ub9cc\ub4e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4.You can create a design by double-clicking mainwindow.ui. &#8212; \uc88c\uce21\uc758 Widget Box\ub97c \uc774\uc6a9\ud574\uc11c \ub2e4\uc74c\uacfc \uac19\uc774 \ud654\uba74\uc744 \uad6c\uc131\ud569\ub2c8\ub2e4.&#8212; objectName\uc740 \uc6b0\uce21\uc758 \ud328\ub110\uc5d0\uc11c \ubc14\uafc0 \uc218 \uc788\uc2b5\ub2c8\ub2e4. 1)\ub808\uc774\uc544\uc6c3:Vertical Layout 2) \ubc84\ud2bc : Push Button==&gt; objectName : pushButton 3)\uc785\ub825 : PlainText Edit==&gt; \uc785\ub8251 : objectName : plainTextEdit==&gt; \uc785\ub8252 : objectName [&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-2131","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\/2131","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=2131"}],"version-history":[{"count":21,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2131\/revisions"}],"predecessor-version":[{"id":2159,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2131\/revisions\/2159"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=2131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=2131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=2131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}