PDA

View Full Version : Singleton or not



cszawisza
17th June 2014, 16:59
Hi!
I'm now developing an application that saves some data in a DB. One of tables in that DB contains files for other associated tables. What I want to do is to generate a SHA256 hash for every file in the DB, and the application should check first if file with such hash is available on disk cache, and if file exists, get it from disk instead of download from the DB. Because those files will be needed in different places in application I decided to use a singleton class that will hold information about files cached on disk, and if some action is needed just ask the singleton class.
Is it good approach, or should I use different one? (setProperty, Q_GLOBAL_STATIC)

anda_skoa
18th June 2014, 11:35
A Q_GLOBAL_STATIC is basically the same thing as a singleton.

The only other option I can see is to explicitly create a single instance of that class and pass it to wherever it is needed.

Cheers,
_