{"id":15,"date":"2006-03-28T23:21:38","date_gmt":"2006-03-29T03:21:38","guid":{"rendered":"http:\/\/thesmithfam.org\/blog\/?p=15"},"modified":"2019-08-12T07:16:33","modified_gmt":"2019-08-12T13:16:33","slug":"qt-more-slots-please","status":"publish","type":"post","link":"https:\/\/thesmithfam.org\/blog\/2006\/03\/28\/qt-more-slots-please\/","title":{"rendered":"Qt: More slots please"},"content":{"rendered":"<p>I&#8217;m usually an avid fanboy of Qt, but the more I use it, the more I find myself wanting two changes:<\/p>\n<p>1. More slots please<br \/>\n2. More control over signals\u00c2\u00a0<\/p>\n<p>Read on for\u00c2\u00a0a couple examples.<\/p>\n<p><!--more--><\/p>\n<p>1. More slots please<\/p>\n<p>It would be great if QComboBox&#8217;s setCurrentText() were a slot. Then I could hook combo-boxes to eachother. I realize that Qt 4 has refactored the setCurrentText() method to require an index too, so this will probably not happen, but it would be helpful.<\/p>\n<p>I would also like QScrollBar to make setMaxValue() a slot. That way I could hook my custom widgets&#8217; maxHScroll() and maxVScroll() signals to it instead of having to write one-liner slots for the sole purpose of passing values straight through to setMaxValue().<\/p>\n<p>2. More control over signals<\/p>\n<p>I always have to guess whether a certain method call will result in a signal being fired. For example. Does QLineEdit::setText() emit a signal? What about QSpinBox::setValue()? What about QCheckbox()? (answers below)<\/p>\n<p>Wouldn&#8217;t it be nice if there were two ways to call QLineEdit::setText(): One that would emit the textChanged() signal and one that would noy? Or better yet: just make setText() <strong>always<\/strong> emit textChanged()!This would save me lots of headache. I like the way that QSpinBox and QCheckbox do it. They emit valueChanged() and toggled() whether the user clicks on them or their values are changed programmatically.<\/p>\n<p>I would also like to see a textChangedFocusLost() signal for QLineEdit. As is, I have to manually track whether the text has <em>really <\/em>changed with my own boolean and the textChanged() signal. Then, on lostFocus() I check that boolean, and if true, I finally know that the text was changed. When you&#8217;ve got a dialog with a couple dozen QLineEdits, that&#8217;s a lot of booleans to keep track of!<\/p>\n<p>Could there be a way to retrieve a list of connections for a widget? It would be nice to know what connections a widget has before mucking with it. That way, I could remove connections, make changes, and restore them at runtime if need be.<\/p>\n<p>Enough rants for one evening. I love Qt. It works far better for me than any other widget toolkit that I&#8217;ve used. It&#8217;s fast, pretty, cross-platform (yes, it really is), and the code is readable. Last night, I was able to take a few thousand lines of Linux Qt code written prior to Qt 2.0, and port it to Qt 3.3.5 for Windows in about 30 minutes. Last year, I ported a 15,000 line Qt application from Linux to Windows in about 16 hours, and I had never used Qt before. If that doesn&#8217;t attest to Qt&#8217;s quality, I don&#8217;t know what will. They&#8217;ve done a great job with Qt. I quite enjoy working with it. In fact, I like it so much, that I plan on using it for non-GUI C++ projects in the future. As of Qt 4, you don&#8217;t even need an event loop. Now that&#8217;s cool!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m usually an avid fanboy of Qt, but the more I use it, the more I find myself wanting two changes: 1. More slots please 2. More control over signals\u00c2\u00a0 Read on for\u00c2\u00a0a couple examples.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-code-and-cruft"],"_links":{"self":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":1,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":1619,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions\/1619"}],"wp:attachment":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}