Results 1 to 2 of 2

Thread: QHash with structure as value

  1. #1
    Join Date
    Jan 2011
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    14

    Default QHash with structure as value

    Hi,

    I need to create QHash where key will be int and value will be structure but I'm just not sure which way is better to either to keep a pointer to the structure

    QHash<int, MyStruct*> myHash;

    or keep the structures by value

    QHash<int, MyStruct> myHash;

    ?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QHash with structure as value

    Depends on how expensive your structure is to copy and assign, if you expect the hash to contain a lot of "empty" entries, whether someone getting a copy of the hash should have access to the same objects or not, etc.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    ArkKup (18th February 2014)

Similar Threads

  1. qhash in qtscript
    By ivareske in forum Qt Programming
    Replies: 0
    Last Post: 18th December 2011, 11:43
  2. Replies: 12
    Last Post: 26th June 2011, 11:26
  3. Replies: 1
    Last Post: 10th February 2009, 09:42
  4. QHash
    By coderbob in forum Qt Programming
    Replies: 2
    Last Post: 2nd July 2008, 14:29
  5. Can QHash::capacity() be smaller than QHash::size()?!?
    By iw2nhl in forum Qt Programming
    Replies: 2
    Last Post: 24th August 2007, 01:17

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.