Results 1 to 4 of 4

Thread: purpose of Q_GLOBAL_STATIC

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Nov 2010
    Posts
    315
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanked 53 Times in 51 Posts

    Default Re: purpose of Q_GLOBAL_STATIC

    When I taken a look how it looks like, it looks like it is working for singletons.
    First call of function NAME will cause creation of singleton and return pointer to that singleton.
    During application clean up this singleton still can be used. In case it was already destroyed function NAME will return null pointer (this will prevent use of dangling pointer).

    Macro is not documented so it shouldn't be used.

    I have doubts how it should be used. Problem is with static keyword.
    If macro is used outside of class in header file it will not be singleton, you will have one instance for each cpp file that included that header.
    If macro is used outside of class in source file it will be visible only in that cpp file.
    If used inside of class this will define inline static method className::NAME so again you will have multiple instances for each use of this method.
    So it doesn't look like this macro is very useful. Only in case when you want have singleton visible only in single source file.
    Last edited by MarekR22; 15th July 2011 at 13:01.

Similar Threads

  1. Navigation purpose
    By jerkymotion in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2011, 17:59
  2. Using Q_GLOBAL_STATIC is the recomendent way?
    By oficjalne100 in forum Qt Programming
    Replies: 2
    Last Post: 10th February 2011, 22:42
  3. How to make a general purpose storage class?
    By khikho in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2009, 23:16

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
  •  
Qt is a trademark of The Qt Company.