[Interest] Heavily Commented Example: Simple Single Frontend with Two Backends
Bo Thorsen
bo at fioniasoftware.dk
Mon Oct 22 07:40:15 CEST 2012
Den 21-10-2012 23:46, d3fault skrev:
>
> On Oct 21, 2012 11:02 AM, "Bo Thorsen" <bo at fioniasoftware.dk
> <mailto:bo at fioniasoftware.dk>> wrote:
> >
> > If you set out to correct the documentation, you should make it better,
> > not go from one one-sided way of thinking to another.
> >
>
> What? Are we talking about the same thing? 99% of the time,
> implementing QThread and overriding run() is not what the user wants
> to do... but that's what the (currently being revised) documentation
> suggests. Sure it's not completely wrong... but that method should be
> just barely mentioned, and only after the better usage (moveToThread)
> is thoroughly explained. There are too many people "doing it wrong"
> (to quote that one article).
>
See, this is where you are wrong. I've heard this claim over and over
again, and that doesn't make it right. Saying that subclassing is only
valid for 1% of the time is just silly. There are plenty of perfectly
fine reasons to do this.
1) If you have pure computations (emitting progress signals can take it
off the list)
2) If you have initialization that has to run in your thread, one way is
to do a run method like this:
run() {
init();
createObjects();
exec();
}
3) moveToThread has problems as well. The worst of them:
thread->moveToThread(thread). I have actually seen this in customer code.
4) By letting the thread instantiate it's object, you probably have
better separation of responsibility. With moveToThread, you don't just
start something where you don't need to know how it's implemented.
That's bad OOP style.
Now, please understand what I'm saying. I do the moveToThread way more
than half the times I use threads, so I agree that it's better in most
cases. The only thing I'm saying here is that when you claim that
subclassing is wrong 99% of the time, that's waaaaaaaay off the mark.
It's a valid tool in the toolbox.
Bo Thorsen.
Come by my DevDays talk in Berlin - "Designing for testability". Learn how to build and run your unit tests with the Qt application.
Fionia Software - Qt experts for hire.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121022/b7ffd067/attachment.html>
More information about the Interest
mailing list