View Full Version : Setting a global variable

10th October 2009, 05: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:



10th October 2009, 08: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).

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


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