{"id":416,"date":"2012-02-13T14:44:20","date_gmt":"2012-02-13T21:44:20","guid":{"rendered":"http:\/\/www.lothlorien.com\/kf6gpe\/?p=416"},"modified":"2012-02-24T11:38:14","modified_gmt":"2012-02-24T18:38:14","slug":"debugging-qts-signal-slot-connections","status":"publish","type":"post","link":"https:\/\/www.lothlorien.com\/kf6gpe\/debugging-qts-signal-slot-connections\/","title":{"rendered":"Debugging Qt&#8217;s signal-slot connections&#8230;"},"content":{"rendered":"<p>What do you do if you think you&#8217;ve correctly connected a signal to a slot and yet your slot&#8217;s not being fired? I ran into that Friday at 5:30pm, just about the time I hoped I&#8217;d call it a day and go home. Fortunately in my case, I was simply passing <code>null<\/code> to connect, and I got a message in the debugging log about trying to connect a signal from a null object. (Unfortunately for me, I didn&#8217;t see the log right away, because of all the other stuff I was dumping to the log.) <\/p>\n<p>If you&#8217;re in the same boat, what do you do to debug the situation? Here&#8217;s a bunch of things to try:<\/p>\n<ul>\n<li>Check the compile log for error messages about undefined signals and slots.<\/li>\n<li>Check the run-time log for errors on connection. If need be, ensure that connect succeeds by testing its return value (it should return <code>true<\/code>.<\/li>\n<li>Check to make sure that the connect code is reached, that the emit code is reached, and the slot code. (Odds are one of them isn&#8217;t.)<\/li>\n<li>Make sure you declare the connection like this:<br \/>\n<code><br \/>\nconnect(sender, SIGNAL(someSignal(type)), receiver, SLOT(received(type)))<br \/>\n<\/code><br \/>\nThe signal and slot specifications should have the argument types, but not the arguments themselves. Moreover, you can omit <code>const<\/code> and reference specifications in the arguments; the meta-object compiler strips them anyway.<\/li>\n<li>Check the parameters of the signal and slot and ensure that they match <i>precisely<\/i><\/li>\n<li>Check to be sure that you&#8217;ve correctly declared the <code>signals<\/code> and <code>slots<\/code> portions of your header correctly.<\/li>\n<li>For that matter, be sure that your sender and receiver both inherit from <code>QObject<\/code>, and that you have <code>Q_OBJECT<\/code> declared in your class definition. (Remember, you need to do both.)<\/li>\n<li>If you&#8217;ve forgotten part of the <code>QObject<\/code> declaration in your header, re-run qmake and rebuild.<\/li>\n<li>Make sure you make the connection with <code>connect<\/code> <i>before<\/i> you invoke any functions that fire the signal. Signals may fire synchronously.<\/li>\n<li>Make sure you&#8217;re not disconnecting the signal anywhere with <code>disconnect<\/code>.\n<\/ul>\n<p>Usually, the problem&#8217;s pretty easy to track down, especially if you check the log and the signal and slot declarations closely. A common mistake is to try to wire a signal to a slot that&#8217;s not been declared a slot, too, so check your headers closely!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What do you do if you think you&#8217;ve correctly connected a signal to a slot and yet your slot&#8217;s not being fired? I ran into that Friday at 5:30pm, just about the time I hoped I&#8217;d call it a day and go home. Fortunately in my case, I was simply passing null to connect, and &hellip; <a href=\"https:\/\/www.lothlorien.com\/kf6gpe\/debugging-qts-signal-slot-connections\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Debugging Qt&#8217;s signal-slot connections&#8230;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9],"tags":[],"class_list":["post-416","post","type-post","status-publish","format-standard","hentry","category-mobile","category-programming"],"_links":{"self":[{"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/posts\/416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/comments?post=416"}],"version-history":[{"count":9,"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/posts\/416\/revisions"}],"predecessor-version":[{"id":427,"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/posts\/416\/revisions\/427"}],"wp:attachment":[{"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/media?parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/categories?post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lothlorien.com\/kf6gpe\/wp-json\/wp\/v2\/tags?post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}