PDA

View Full Version : Using Q_GLOBAL_STATIC is the recomendent way?



oficjalne100
10th February 2011, 17:24
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?

franz
10th February 2011, 17:34
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?

wysota
10th February 2011, 23:42
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.