{"id":1,"date":"2023-05-12T17:13:34","date_gmt":"2023-05-12T17:13:34","guid":{"rendered":"https:\/\/www.sofar.ltd\/?p=1"},"modified":"2023-05-16T21:06:42","modified_gmt":"2023-05-16T13:06:42","slug":"hello-world","status":"publish","type":"post","link":"https:\/\/www.sofar.ltd\/?p=1","title":{"rendered":"Qt\u4fe1\u53f7\u548c\u69fd\u7684\u4e00\u4e9b\u8865\u5145"},"content":{"rendered":"\n<p>\u5728Qt\u5de5\u7a0b\u4e2d\uff0c\u4e00\u4e2a\u7c7b\u82e5\u8981\u652f\u6301\u4fe1\u53f7\u548c\u69fd\uff0c\u5c31\u5fc5\u987b\u4ece QObject \u6216 QObject \u7684\u5b50\u7c7b\u7ee7\u627f\uff0c\u540c\u65f6\u9700\u8981\u5728\u5934\u6587\u4ef6\u7c7b\u58f0\u660e\u7684\u5f00\u5934\u5f15\u5165 Q_OBJECT \u5b8f\u3002<\/p>\n\n\n\n<p>\u4fe1\u53f7\u548c\u69fd\u7684\u8fde\u63a5\u4f7f\u7528connect\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-tertiary-background-color has-background\"><code>connect(const QObject *sender,\n        PointerToMemberFunction signal,\n        const QObject *receiver,\n        PointerToMemberFunction method,\n        Qt::ConnectionType type=Qt::AutoConnection);\n\nconnect(const QObject *sender,\n        PointerToMemberFunction signal,\n        Functor functor);\n        \/* Lambda expression can also be used. *\/<\/code><\/pre>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-tertiary-background-color has-background\"><code>QLabel *label = new QLabel;\nQLineEdit *lineEdit = new QLineEdit;\nQObject::connect(lineEdit, &amp;QLineEdit::textChanged,\n                        label, QLabel::setText);<\/code><\/pre>\n\n\n\n<p>\u82e5\u5728\u53d1\u9001\u8005\u7c7b\u4e2d\u4fe1\u53f7\u5b58\u5728\u91cd\u8f7d\uff0c\u8fde\u63a5\u4fe1\u53f7\u9700\u8981\u4f7f\u7528 QOverload&lt; &gt;::of( )\u6216 static_cast&lt;&gt;()\u6765\u6307\u5b9a\u7c7b\u578b\u3002\u4f8b\u5982\u5728 QComboBox \u4e2d\u5173\u4e8ecurrentIndexChanged\u6709\u4e24\u4e2a\u4fe1\u53f7\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-tertiary-background-color has-background\"><code>void QComboBox::currentIndexChanged(const QString &amp;text)\nvoid QComboBox::currentIndexChanged(int index)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-tertiary-background-color has-background\"><code>connect(comboBox,\n        QOverload&lt;const QString &amp;&gt;::of( &amp;QComboBox::currentIndexChanged),\n        &#91;=](const QString &amp;text){ \/* ... *\/ });\n\nconnect(comboBox,\n        static_cast&lt;void (QComboBox::*)(int)&gt;(&amp;QComboBox::currentIndexChanged),\n        &#91;=](int index){\/* ... *\/});<\/code><\/pre>\n\n\n\n<p>\u9898\u56fe\u6765\u81ea<a href=\"https:\/\/pixabay.com\/zh\/photos\/lighthouse-ocean-sea-coast-travel-1872998\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pixabay<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Qt\u5de5\u7a0b\u4e2d\uff0c\u4e00\u4e2a\u7c7b\u82e5\u8981\u652f\u6301\u4fe1\u53f7\u548c\u69fd\uff0c\u5c31\u5fc5\u987b\u4ece QObject \u6216 QObject \u7684\u5b50\u7c7b\u7ee7\u627f\uff0c\u540c\u65f6\u9700\u8981\u5728\u5934\u6587 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":33,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":6,"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/41"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=\/wp\/v2\/media\/33"}],"wp:attachment":[{"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sofar.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}