Results 1 to 4 of 4

Thread: Setting a global variable

  1. #1
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Setting a global variable

    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

    Thanks

    andre

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Setting a global variable

    Sounds to me that you are searching for a singleton pattern: See the our wiki article.

  3. #3
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting a global variable

    Have look at this link:

    [link] http://www.gamedev.net/reference/art...rticle1798.asp[/link]

  4. #4
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting a global variable

    If you need just one object exactly then you can declare one static with global visibility.
    -- Tanuki

    per cauda vel vaculus cauda

Similar Threads

  1. how to declare a global variable right
    By Cruz in forum Newbie
    Replies: 13
    Last Post: 16th February 2010, 16:25
  2. linking a slider to a global variable
    By switch in forum Newbie
    Replies: 6
    Last Post: 5th August 2009, 08:02
  3. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  4. Link QVariant to global variable
    By jobrandt in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2007, 10:18
  5. global variable
    By Shuchi Agrawal in forum General Programming
    Replies: 10
    Last Post: 15th February 2007, 04:19

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.