{"id":172,"date":"2014-04-21T10:49:56","date_gmt":"2014-04-21T02:49:56","guid":{"rendered":"http:\/\/www.datarelab.com\/blog\/?p=172"},"modified":"2014-04-21T10:49:56","modified_gmt":"2014-04-21T02:49:56","slug":"qt%3a%3aconnectiontype%20%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/Technical_literature\/172.html","title":{"rendered":"Qt::ConnectionType \u89e3\u6790"},"content":{"rendered":"<p>signal\/slot\u5728\u5e95\u5c42\u4f1a\u4f7f\u7528\u4e09\u79cd\u65b9\u5f0f\u4f20\u9012\u6d88\u606f\u3002\u53c2\u89c1QObject::connect()\u65b9\u6cd5\uff1a<br \/>\nbool QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * method, Qt::ConnectionType type = Qt::AutoCompatConnection )<br \/>\n\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u662f\u5c31\u662f\u4f20\u9012\u6d88\u606f\u7684\u65b9\u5f0f\u4e86\uff0c\u6709\u56db\u4e2a\u53d6\u503c\uff1a<\/p>\n<p>Qt::DirectConnection<br \/>\nWhen emitted, the signal is immediately delivered to the slot.<br \/>\n\u5047\u8bbe\u5f53\u524d\u67094\u4e2aslot\u8fde\u63a5\u5230QPushButton::clicked(bool)\uff0c\u5f53\u6309\u94ae\u88ab\u6309\u4e0b\u65f6\uff0cQT\u5c31\u628a\u8fd94\u4e2aslot\u6309\u8fde\u63a5\u7684\u65f6\u95f4\u987a\u5e8f\u8c03\u7528\u4e00\u904d\u3002\u663e\u7136\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u80fd\u8de8\u7ebf\u7a0b\uff08\u4f20\u9012\u6d88\u606f\uff09\u3002<\/p>\n<p>Qt::QueuedConnection<br \/>\nWhen emitted, the signal is queued until the event loop is able to deliver it to the slot.<br \/>\n\u5047\u8bbe\u5f53\u524d\u67094\u4e2aslot\u8fde\u63a5\u5230QPushButton::clicked(bool)\uff0c\u5f53\u6309\u94ae\u88ab\u6309\u4e0b\u65f6\uff0cQT\u5c31\u628a\u8fd9\u4e2asignal\u5305\u88c5\u6210\u4e00\u4e2a QEvent\uff0c\u653e\u5230\u6d88\u606f\u961f\u5217\u91cc\u3002QApplication::exec()\u6216\u8005\u7ebf\u7a0b\u7684QThread::exec()\u4f1a\u4ece\u6d88\u606f\u961f\u5217\u91cc\u53d6\u6d88\u606f\uff0c\u7136\u540e\u8c03\u7528 signal\u5173\u8054\u7684\u51e0\u4e2aslot\u3002\u8fd9\u79cd\u65b9\u5f0f\u65e2\u53ef\u4ee5\u5728\u7ebf\u7a0b\u5185\u4f20\u9012\u6d88\u606f\uff0c\u4e5f\u53ef\u4ee5\u8de8\u7ebf\u7a0b\u4f20\u9012\u6d88\u606f\u3002<\/p>\n<p>Qt::BlockingQueuedConnection<br \/>\nSame as QueuedConnection, except that the current thread blocks until the slot has been delivered. This connection type should only be used for receivers in a different thread. Note that misuse of this type can lead to dead locks in your application.<br \/>\n\u4e0eQt::QueuedConnection\u7c7b\u4f3c\uff0c\u4f46\u662f\u4f1a\u963b\u585e\u7b49\u5230\u5173\u8054\u7684slot\u90fd\u88ab\u6267\u884c\u3002\u8fd9\u91cc\u51fa\u73b0\u4e86\u963b\u585e\u8fd9\u4e2a\u8bcd\uff0c\u8bf4\u660e\u5b83\u662f\u4e13\u95e8\u7528\u6765\u591a\u7ebf\u7a0b\u95f4\u4f20\u9012\u6d88\u606f\u7684\u3002<\/p>\n<p>Qt::AutoConnection<br \/>\nIf the signal is emitted from the thread in which the receiving object lives, the slot is invoked directly, as with Qt::DirectConnection; otherwise the signal is queued, as with Qt::QueuedConnection.<br \/>\n\u8fd9\u79cd\u8fde\u63a5\u7c7b\u578b\u6839\u636esignal\u548cslot\u662f\u5426\u5728\u540c\u4e00\u4e2a\u7ebf\u7a0b\u91cc\u81ea\u52a8\u9009\u62e9Qt::DirectConnection\u6216Qt::QueuedConnection<\/p>\n<p>\u8fd9\u6837\u770b\u6765\uff0c\u7b2c\u4e00\u79cd\u7c7b\u578b\u7684\u6548\u7387\u80af\u5b9a\u6bd4\u7b2c\u4e8c\u79cd\u9ad8\uff0c\u6bd5\u7adf\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u9700\u8981\u5c06\u6d88\u606f\u5b58\u50a8\u5230\u961f\u5217\uff0c\u800c\u4e14\u53ef\u80fd\u4f1a\u6d89\u53ca\u5230\u5927\u5bf9\u8c61\u7684\u590d\u5236\uff08\u8003\u8651sig_produced(BigObject bo)\uff0cbo\u9700\u8981\u590d\u5236\u5230\u961f\u5217\u91cc\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>signal\/slot\u5728\u5e95\u5c42\u4f1a\u4f7f\u7528\u4e09\u79cd\u65b9\u5f0f\u4f20\u9012\u6d88\u606f\u3002\u53c2\u89c1QObject::connect()\u65b9\u6cd5\uff1a bool  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[152],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-Technical_literature","tag-qt"],"views":1238,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}