PDA

View Full Version : Setting a global variable



Windsoarer
10th October 2009, 04:57
Hi gurus,

To express it simply, my problem is to access, from different classes, an instance of the object QThing.

It is possible to declare the object as a member variable in one class, and then exchange pointers *pCurrentThing with other classes. However, each time the active instance of the object changes, all the pointers in the other classes need to be updated.

Is there a way to declare a global pointer *g_pCurrentThing, for instance at "main" level, which could be seen by all the classes ? I've been unsuccessful so far.

Hope this is understandable :confused:

Thanks

andre

Lykurg
10th October 2009, 07:08
Sounds to me that you are searching for a singleton pattern: See the our wiki article (http://wiki.qtcentre.org/index.php?title=Singleton_pattern).

toutarrive
16th February 2010, 11:41
Have look at this link:

http://www.gamedev.net/reference/articles/article1798.asp

Tanuki-no Torigava
16th February 2010, 22:37
If you need just one object exactly then you can declare one static with global visibility.