@kshegunov
I understand, and respect your opinion on the matter but... I doesn't agree with most of them. Not wanting to make a big discussion of it, (mainly 'cause it's really out of the scope of the post) but...
let's see:
A singleton is not a real object, it's a facade for a global variable
Well, yeah. I would say it's a (much) more elegant way to create a "global variable", since it ensures that only one will be created.
A singleton created on the stack is initialized before main, so anything that actually depends on things done in main() as QObject does, may or may not work.
Well, the way I learned to implement singleton on C++ uses heap.
A singleton that's constructed on the heap often is simply left undeleted - a memory leak. C++ is not JAVA, it's the programmers job to clean the memory up.
Well, I'm not seeing a problem here. I dont mind putting a few deletes at the end of my main, or even connecting some signals.
A singleton that's created on first use in the heap requires special measures to be taken, so the construction is thread safe.
Again, not seeing a problem here, just a need to take some caution when coding.
A singleton created on the stack can't guarantee order of initialization (whence point 2 derives). If you have more than one the loader will initialize them depending on its mood!
Again, I don't create them on stack.
A singleton that's created on the heap can't guarantee order of initialization ever!
Not really sure what you mean here.
A singleton is a global shared public resource in your application that promotes coupling, it actually couples every one of the classes that decide to use it.
Some times you need that coupling. You need to center the processing in one point in the code. That's what controllers are all about.
A singleton is not thread-safe by design, and can't be reentrant as there is only one.
Not really. For data classes, you're right. But for controllers, they can be thread safe as long as their attributes are read-only
Why your worker object should not be a singleton
My worker object is not a singleton. My controller object (the one that creates the worker objects) is.
The fact that something is called a "design pattern" in some book, doesn't mean you should use it.
But means that it have its uses.