Results 1 to 3 of 3

Thread: Using Q_GLOBAL_STATIC is the recomendent way?

  1. #1
    Join Date
    Dec 2010
    Posts
    28
    Thanks
    6
    Thanked 10 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Using Q_GLOBAL_STATIC is the recomendent way?

    Hi

    When I study qt/example/network/torrent client I discovered non documented macro named Q_GLOBAL_STATIC. I suspect that it resolves classic problem with global singleton objects which are not created on stack nor as class member variable nor in main function but exists alone under pointer in obj file (like in classic C). I am very keen to use this macro, but I am worry why they do not documented it. I am afraid that they do not recommended that macro, but why they used it??? I hang my project now and I must make decision - use that macro or not?

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using Q_GLOBAL_STATIC is the recomendent way?

    You can use it fairly safely. It's in qglobal.h which is part of the interface definition, and they aren't going to change that lightly. Even if they would not recommend using it, they use it themselves...

    Anyway, here's something to think about: do you really need globals?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. The following user says thank you to franz for this useful post:

    oficjalne100 (10th February 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using Q_GLOBAL_STATIC is the recomendent way?

    I don't see how you could benefit from this macro. It doesn't solve any particular problem apart from keeping the default namespace relatively clean by defining a local function that internally keeps an instance to a global variable and returns a pointer to it. You can as well declare a global object directly and use it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.