Results 1 to 3 of 3

Thread: QHash <int, class*>

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: QHash <int, class*>

    You need to call i.next() before taking the value with i.value() (btw. its in the first example in QHashIterator documentation):
    Qt Code:
    1. while (i.hasNext()) {
    2. i.next();
    3. qDebug()<<i.key();
    4. Person *per = i.value();
    5. if( per ){ // better check before dereferencing a pointer
    6. qDebug()<< "Name: " << per->m_name << "Number: "<<per->m_number;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    also if I call hash.clear() at the end do I need to delete the value first or clear() will take care of it ?
    Yes you need to delete allocated values yourself, QHash does not know what kind of data you keep inside it.

  2. The following user says thank you to stampede for this useful post:

    ArkKup (19th December 2011)

Similar Threads

  1. qhash with custom class
    By dognzhe in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 06:30
  2. Replies: 1
    Last Post: 10th February 2009, 09:42
  3. How to store custom class in QHash?
    By Misenko in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 08:57
  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.