{"id":49,"date":"2009-03-12T10:31:44","date_gmt":"2009-03-12T16:31:44","guid":{"rendered":"http:\/\/hg.unl.edu\/~koleson\/wordpress\/?p=49"},"modified":"2009-03-12T10:31:44","modified_gmt":"2009-03-12T16:31:44","slug":"starting-with-the-qt-framework","status":"publish","type":"post","link":"https:\/\/www.jusquici.org\/blog\/?p=49","title":{"rendered":"Starting with the Qt Framework"},"content":{"rendered":"<p>Although I&#8217;m far from using Linux as my main OS, I have started using it side-by-side with OS X on my desktop. \u00c2\u00a0It holds a lot of promise, particularly seeing a sort of renaissance associated with the rise of Ubuntu.<\/p>\n<p>On the other hand, the flexibility Linux gives to users and developers can be intimidating to deal with coming from more rigid worlds like those of Mac OS and Windows. \u00c2\u00a0Regardless of what you feel about .NET and Cocoa, they&#8217;re at least <em>consistent.<\/em> <em> <\/em>Even with the improved standardization of Linux distributions and the stability of their library APIs, it&#8217;s a far cry from the safety of the world of the two more popular systems.<\/p>\n<p>For several years now, Qt Software (formerly Trolltech, now owned wholly by Nokia) has offered a consistent and full-featured C++ toolkit not only for Linux but across Mac OS X and Windows as well. \u00c2\u00a0It is offered in both commercial and, more recently, LGPL distributions.<\/p>\n<p>Obviously a consistent, OS-native, non-bytecode-based toolkit is very desirable for performance reasons, but Qt makes another excellent addition to C++ that makes development a joy: \u00c2\u00a0<em>slots and signals<\/em>.<\/p>\n<p>It&#8217;s an implementation of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Observer_pattern\">Observer design pattern<\/a> that&#8217;s excellent for asynchronous operations that are common in GUI applications. \u00c2\u00a0Importantly, it allows run-time registration of receivers and multiple-target signals, which we say are <em>emitted<\/em> from an object and received by the registered slot of other objects.<\/p>\n<p>For example, suppose we have set up a button in our Qt GUI named &#8220;myButton&#8221; which emits, aptly, &#8220;clicked()&#8221; as a signal when it is clicked. \u00c2\u00a0We would like to call the void function &#8220;calculate()&#8221; of the object &#8220;myCalculator&#8221; when myButton is clicked. \u00c2\u00a0We can register this relationship with this single line of code:<\/p>\n<blockquote><p><code>connect(myButton, SIGNAL(clicked()), myCalculator, SLOT(calculate()));<\/code><\/p><\/blockquote>\n<p>Obviously, this isn&#8217;t the most powerful example of this mechanism since it&#8217;s merely a one-to-one relationship, but realize a signal may emit to several slots, and slots may receive signals from multiple objects, and you start to see how code can be simplified and made more intuitive.<\/p>\n<p>More to come.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Although I&#8217;m far from using Linux as my main OS, I have started using it side-by-side with OS X on my desktop. \u00c2\u00a0It holds a lot of promise, particularly seeing a sort of renaissance associated with the rise of Ubuntu. On the other hand, the flexibility Linux gives to users and developers can be intimidating &hellip; <a href=\"https:\/\/www.jusquici.org\/blog\/?p=49\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Starting with the Qt Framework<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_markdown_editor_remember":false,"footnotes":""},"categories":[1],"tags":[25],"_links":{"self":[{"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/49"}],"collection":[{"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=49"}],"version-history":[{"count":3,"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jusquici.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}