Results 1 to 2 of 2

Thread: Singleton or not

  1. #1
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Singleton or not

    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)

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Singleton or not

    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,
    _

Similar Threads

  1. Qt Singleton Class
    By alexismedina in forum Newbie
    Replies: 3
    Last Post: 22nd June 2010, 17:03
  2. Singleton Menu!
    By ArlexBee-871RBO in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2009, 11:32
  3. Replies: 2
    Last Post: 8th October 2006, 17:49
  4. Singleton pattern - end in recursion
    By probine in forum General Programming
    Replies: 6
    Last Post: 29th March 2006, 14:08
  5. trying to use singleton pattern
    By therealjag in forum Newbie
    Replies: 3
    Last Post: 20th February 2006, 02:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.