{"id":631,"date":"2023-04-12T23:27:08","date_gmt":"2023-04-12T15:27:08","guid":{"rendered":"https:\/\/lolife.top\/?p=631"},"modified":"2023-04-12T23:27:08","modified_gmt":"2023-04-12T15:27:08","slug":"qt%e4%b8%ad%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%92%8c%e6%a7%bd","status":"publish","type":"post","link":"https:\/\/lolife.top\/?p=631","title":{"rendered":"QT\u4e2d\u7684\u4fe1\u53f7\u548c\u69fd"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4fe1\u53f7\u548c\u69fd<\/h2>\n\n\n\n<p>\u4fe1\u53f7\u4e0e\u69fd\uff08Signal &amp; Slot\uff09\u662f Qt \u7f16\u7a0b\u7684\u57fa\u7840\uff0c\u4e5f\u662f Qt \u7684\u4e00\u5927\u521b\u65b0\u3002\u56e0\u4e3a\u6709\u4e86\u4fe1\u53f7\u4e0e\u69fd\u7684\u7f16\u7a0b\u673a\u5236\uff0c\u5728 Qt \u4e2d\u5904\u7406\u754c\u9762\u5404\u4e2a\u7ec4\u4ef6\u7684\u4ea4\u4e92\u64cd\u4f5c\u65f6\u53d8\u5f97\u66f4\u52a0\u76f4\u89c2\u548c\u7b80\u5355\u3002\u5b83\u53ef\u4ee5\u8ba9\u5e94\u7528\u7a0b\u5e8f\u7f16\u7a0b\u4eba\u5458\u628a\u8fd9\u4e9b\u4e92\u4e0d\u4e86\u89e3\u7684\u5bf9\u8c61\u7ed1\u5b9a\u5728\u4e00\u8d77\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4fe1\u53f7\uff08Signal\uff09<\/h2>\n\n\n\n<p>\u4fe1\u53f7\uff08Signal\uff09\u5c31\u662f\u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\u88ab\u53d1\u5c04\u7684\u4e8b\u4ef6\uff0c\u4f8b\u5982PushButton \u6700\u5e38\u89c1\u7684\u4fe1\u53f7\u5c31\u662f\u9f20\u6807\u5355\u51fb\u65f6\u53d1\u5c04\u7684 clicked() \u4fe1\u53f7\uff0c\u4e00\u4e2a ComboBox \u6700\u5e38\u89c1\u7684\u4fe1\u53f7\u662f\u9009\u62e9\u7684\u5217\u8868\u9879\u53d8\u5316\u65f6\u53d1\u5c04\u7684 CurrentIndexChanged() \u4fe1\u53f7\u3002<br>GUI \u7a0b\u5e8f\u8bbe\u8ba1\u7684\u4e3b\u8981\u5185\u5bb9\u5c31\u662f\u5bf9\u754c\u9762\u4e0a\u5404\u7ec4\u4ef6\u7684\u4fe1\u53f7\u7684\u54cd\u5e94\uff0c\u53ea\u9700\u8981\u77e5\u9053\u4ec0\u4e48\u60c5\u51b5\u4e0b\u53d1\u5c04\u54ea\u4e9b\u4fe1\u53f7\uff0c\u5408\u7406\u5730\u53bb\u54cd\u5e94\u548c\u5904\u7406\u8fd9\u4e9b\u4fe1\u53f7\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u69fd\uff08Slot\uff09<\/h2>\n\n\n\n<p>\u5c31\u662f\u5bf9\u4fe1\u53f7\u54cd\u5e94\u7684\u51fd\u6570\u3002\u69fd\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u4e0e\u4e00\u822c\u7684C++\u51fd\u6570\u662f\u4e00\u6837\u7684\uff0c\u53ef\u4ee5\u5b9a\u4e49\u5728\u7c7b\u7684\u4efb\u4f55\u90e8\u5206\uff08public\u3001private \u6216 protected\uff09\uff0c\u53ef\u4ee5\u5177\u6709\u4efb\u4f55\u53c2\u6570\uff0c\u4e5f\u53ef\u4ee5\u88ab\u76f4\u63a5\u8c03\u7528\u3002\u69fd\u51fd\u6570\u4e0e\u4e00\u822c\u7684\u51fd\u6570\u4e0d\u540c\u7684\u662f\uff1a\u69fd\u51fd\u6570\u53ef\u4ee5\u4e0e\u4e00\u4e2a\u4fe1\u53f7\u5173\u8054\uff0c\u5f53\u4fe1\u53f7\u88ab\u53d1\u5c04\u65f6\uff0c\u5173\u8054\u7684\u69fd\u51fd\u6570\u88ab\u81ea\u52a8\u6267\u884c\u3002<br>\u4fe1\u53f7\u4e0e\u69fd\u5173\u8054\u662f\u7528 QObject::connect() \u51fd\u6570\u5b9e\u73b0\u7684\uff0c\u5176\u57fa\u672c\u683c\u5f0f\u662f\uff1a<br>QObject::connect(sender, SIGNAL(signal()), receiver, SLOT(slot()));<br>\u53c2\u65701\u3001\u4fe1\u53f7\u7684\u53d1\u9001\u8005<br>\u53c2\u65702\u3001\u53d1\u9001\u7684\u4fe1\u53f7<br>\u53c2\u65703\u3001\u4fe1\u53f7\u7684\u63a5\u6536\u8005<br>\u53c2\u65704\u3001\u5904\u7406\u51fd\u6570\uff08\u69fd\u51fd\u6570\uff09<br><\/p>\n\n\n\n<p>\u73b0\u5728\u6211\u4eec\u5728Widget\u7c7b\u4e2d\u52a0\u4e0a\u4e00\u4e2aQPushButton\u6309\u952e\uff0c\u8fd9\u65f6\u6211\u4eec\u5728QT\u7a0b\u5e8f\u4e2d\u70b9\u51fb\u8fd9\u4e2a\u6309\u952e\u63a7\u4ef6\u662f\u6ca1\u6709\u53cd\u5e94\u7684\uff0c\u73b0\u5728\u6211\u4eec\u5e0c\u671b\u70b9\u51fb\u8be5\u6309\u952e\uff0c\u53ef\u4ee5\u5c06\u7a97\u53e3\u5173\u95ed\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u5f97\u7ed9\u5b83\u4eec\u5efa\u7acb\u4fe1\u53f7\u548c\u69fd\u7684\u8054\u7cfb\uff1a<\/p>\n\n\n\n<p>\u9996\u5148\u662fQPushButton\u7c7b\uff1a\u5728\u5b83\u7684\u7236\u7c7b\u4e2d\uff0c\u6211\u4eec\u53d1\u73b0\u5b83\u6709\u8fd9\u4e48\u4e00\u4e2a\u51fd\u6570\uff1avoid checked()\uff0c\u8fd9\u5c31\u662f\u4e00\u4e2a\u4fe1\u53f7\uff0c\u70b9\u51fb\u540e\u89e6\u53d1\u7684\u4fe1\u53f7\uff1b<\/p>\n\n\n\n<p>\u63a5\u7740\u662fWidget\u7c7b\uff1a\u5728\u8fd9\u4e2a\u7c7b\u4e2d\u4e5f\u6709\u8fd9\u4e48\u4e00\u4e2a\u51fd\u6570\uff1abool close()\uff0c\u8fd9\u5c31\u662f\u69fd\uff0c\u4e5f\u53ef\u4ee5\u7406\u89e3\u4e3a\u54cd\u5e94\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u5f53\u6709\u4e86\u4fe1\u53f7\u548c\u69fd\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5efa\u7acb\u8d77\u5b83\u4eec\u4e4b\u95f4\u7684\u8054\u7cfb\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>connect(btn,&amp;QPushButton::clicked,this,&amp;Widget::close);\/\/btn\u662f\u4e00\u4e2aQPushButton\u5bf9\u8c61<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u4fe1\u53f7\u548c\u69fd\u662f\u9700\u8981\u5728\u524d\u9762\u52a0\u4e0a\u2018&amp;\u2019\u7684\u3002<\/p>\n\n\n\n<p>\u5728\u6211\u4eec\u8fd0\u884c\u540e\uff0c\u70b9\u51fb\u8be5\u6309\u94ae\uff0c\u5c31\u53ef\u4ee5\u5173\u95ed\u7a97\u53e3\u4e86<\/p>\n\n\n\n<p>\u672c\u6765\u6ca1\u6709\u8fde\u63a5\u7684\u4e24\u4e2a\u5bf9\u8c61\uff0c\u8fde\u63a5\u5728\u4e00\u8d77\u3002\u672c\u6765\u70b9\u51fb\u6309\u94ae\uff0c\u8ddf\u5173\u95ed\u7a97\u53e3\u6ca1\u6709\u8054\u7cfb\uff0c\u6211\u4eec\u53ef\u4ee5\u540cconnect\u8ba9\u4ed6\u4eec\u5efa\u7acb\u8d77\u8054\u7cfb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4fe1\u53f7\u548c\u69fd \u4fe1\u53f7\u4e0e\u69fd\uff08Signal &amp; Slot\uff09\u662f Qt \u7f16\u7a0b\u7684\u57fa\u7840\uff0c\u4e5f\u662f Qt \u7684\u4e00\u5927\u521b\u65b0\u3002\u56e0\u4e3a\u6709\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":336,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,21],"tags":[],"class_list":["post-631","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-c","category-qt"],"_links":{"self":[{"href":"https:\/\/lolife.top\/index.php?rest_route=\/wp\/v2\/posts\/631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lolife.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lolife.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lolife.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lolife.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=631"}],"version-history":[{"count":1,"href":"https:\/\/lolife.top\/index.php?rest_route=\/wp\/v2\/posts\/631\/revisions"}],"predecessor-version":[{"id":632,"href":"https:\/\/lolife.top\/index.php?rest_route=\/wp\/v2\/posts\/631\/revisions\/632"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lolife.top\/index.php?rest_route=\/wp\/v2\/media\/336"}],"wp:attachment":[{"href":"https:\/\/lolife.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lolife.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lolife.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}