Note that there are some explanatory texts on larger screens.

plurals
  1. POAre Singletons EVIL in GUI Programming with Qt?
    text
    copied!<p>I'm just starting my first fairly large Qt project which will be mostly a bunch of screens with buttons, tab widgets, and Qwt Plots. The panel stack pattern described in <a href="http://doc.trolltech.com/qq/qq27-panelstack.html" rel="nofollow">Qt Quarterly 27</a> seems pretty nice for my application. Each of my screens is a QWidget encapsulated in a Panel which is shown/hidden by a QStackedWidget. However it uses a <strong>singleton pattern</strong> for each Panel so that they aren't all created immediately as the app starts and so that more than one of each screen isn't ever created. </p> <p>So I started coding. Got the panel stack working. Added some code so that dynamically updating widgets aren't dynamically updating all the time. Got my history stack/back button working for the panels. Everything seems just fine, but I've got one nagging worry:</p> <ol> <li>My code smells.</li> </ol> <p>I am in no place to argue with any of the hate posted here and on blogs about the singleton pattern. I think I get it and the code I've written does make me feel a bit dirty with all the boilerplate lines and global objects. But I do like not having to worry about whether or not I already instantiated a screen before switching to it and adding it to my history stack. I just say switch to that screen, it's added to my history stack, and the magic works.</p> <p>From what I've read there are also some cases where singletons can be worthwhile. Is this one of those special cases? The magic screen switching / history stack makes me think 'yes' but the sheer number of different singleton classes I'm going to have to create makes me think 'NO no NO NO NO'.</p> <p>I want to just man up and figure out how to get the singleton pattern out of my code <strong>now</strong> so that I don't have to do it later. But I don't want to get rid of all my singleton classes just to get rid of my singleton classes because they're EVIL [citation needed].</p> <p>Any input is much appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload