Results 1 to 5 of 5

Thread: static QMap doesn't seem to remain static (or at least keeps becoming empty)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: static QMap doesn't seem to remain static (or at least keeps becoming empty)

    Why make it static? Make it global but non-static. If you make it static, it'll only be available in one compilation unit and you'll need to create two global functions to access it from other compilation units. Try this instead:

    In one of implementation files:
    Qt Code:
    1. namespace ExaltedData {
    2. QMap<QString,NatureData> natures;
    3. }
    To copy to clipboard, switch view to plain text mode 

    and in every file which needs to use it add:
    Qt Code:
    1. namespace ExaltedData {
    2. extern QMap<QString,NatureData> natures;
    3. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Enschede, NL, EU
    Posts
    19
    Qt products
    Qt3
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: static QMap doesn't seem to remain static (or at least keeps becoming empty)

    That worked like a charm, although it does seem a bit counterintuitive.

    Thanks

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12

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
  •  
Qt is a trademark of The Qt Company.