{"id":1557,"date":"2020-05-15T16:16:44","date_gmt":"2020-05-15T08:16:44","guid":{"rendered":"http:\/\/bloo.heing.fun\/?p=1557"},"modified":"2020-06-14T12:38:43","modified_gmt":"2020-06-14T04:38:43","slug":"qt5-signal-slots","status":"publish","type":"post","link":"https:\/\/bloo.heing.fun\/?p=1557","title":{"rendered":"Qt5 Signal Slots"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/\/\n#include &lt;QObject>\n\nclass Counter : public QObject\n{\n    Q_OBJECT\n\npublic:\n    Counter() { m_value = 0; }\n\n    int value() const { return m_value; }\n\npublic slots:\n    \/\/ \u4e0d\u662f\u8c03\u7528emit\u7684\u90fd\u8981\u58f0\u660e\u4e3aslots,\u8fd9\u91cc\u58f0\u660e\u662f\u56e0\u4e3a\u8981\u8ba9\u4ed6\u6210\u4e3asignal\n    \/\/ slots\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u5c11\u4e8esignal\u7684\u53c2\u6570\u3002\n    void setValue(int value) {\n        if (value != m_value) {\n            m_value= value;\n            emit valueChanges(value);\n        }\n    }\n\n\/\/ \u5b9a\u4e49\u4e00\u4e2asignal, signal\u53ea\u80fd\u662fvoid\u7c7b\u578b\n\/\/ signal\u4ee3\u7801\u6709moc\u81ea\u52a8\u751f\u6210\uff0c\u4e0d\u9700\u8981\u81ea\u5df1\u53bb\u5b9e\u73b0\u8fd9\u4e2a\u65b9\u6cd5\nsignals:\n    void valueChanged(int newValue);\n\nprivate:\n    int m_value;\n};<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4f7f\u7528\u793a\u4f8b1 \u4e0d\u597d\u7684\u505a\u6cd5\n    connect(ui->startBtn, &amp;QPushButton::released, this,&amp;MainWindow::startGame);\n\/\/ \u4f7f\u7528\u793a\u4f8b2 \u5b89\u5168\u7684\u505a\u6cd5\n\/\/ \u8fd9\u91ccSIGNAL,SLOT\u5b8f\uff0c\u4f30\u8ba1\u662f\u7ed9 \u53c2\u6570 \u751f\u6210 \u51fd\u6570\u7b7e\u540d\uff0c\u4ece\u800c\u5224\u65ad\u662f\u5426\u5b89\u5168\n\/\/ \u51fa\u73b0\u5728SLOT\u5b8f\u4e2d\u7684\u51fd\u6570\uff0c\u9700\u8981 \u58f0\u660e\u7c7b\u6210\u5458\u51fd\u6570\u65f6\uff0c\u7528public signal:\nconnect(ui->startBtn, SIGNAL(released()), this, SLOT(startGame()));\nconnect(scrollBar, SIGNAL(valueChanged(int)),label,  SLOT(setNum(int)));\n\n-----------------------------\n<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528Lambda:<br><a href=\"https:\/\/blog.csdn.net\/csm201314\/article\/details\/77914281\">https:\/\/blog.csdn.net\/csm201314\/article\/details\/77914281<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Lambda:https:\/\/blog.csdn.net\/csm201314\/article\/detail [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76,36],"tags":[],"class_list":["post-1557","post","type-post","status-publish","format-standard","hentry","category-cplusplus","category-36"],"_links":{"self":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1557"}],"version-history":[{"count":7,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1557\/revisions"}],"predecessor-version":[{"id":1665,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1557\/revisions\/1665"}],"wp:attachment":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}