Results 1 to 4 of 4

Thread: iterate through QHash

  1. #1
    Join Date
    Apr 2010
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default iterate through QHash

    I made a loop :
    Qt Code:
    1. QHashIterator<QString, QString> i(customers);
    2. while (i.hasNext())
    3. {
    4.  
    5. QString dir=(i.value().left(1)=="-")?"1":"0";
    6. ...
    To copy to clipboard, switch view to plain text mode 
    but runtime error is on i.value():
    Qt Code:
    1. The inferior stopped because it received a signal from
    2. the operating system.
    3. signal name: SIGABRT
    4. signal meaning: Aborted
    To copy to clipboard, switch view to plain text mode 
    whats problem?
    Last edited by rosenth; 23rd May 2010 at 04:54.

  2. #2
    Join Date
    Apr 2010
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: iterate through QHash

    forget to add:
    Qt Code:
    1. i.next();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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: iterate through QHash

    Hint: Instead of left() better use QString::startsWith() (or QString::at()) since their performance is more effective.

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: iterate through QHash

    Try inspecting your hash table to see if what it contains makes sense. Try walking through it using hash.keys() instead of using an iterator; if that works, the problem lies with the iterator, not your hash table.

Similar Threads

  1. How to iterate QMap twice
    By sophister in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2009, 16:59
  2. Replies: 1
    Last Post: 10th February 2009, 09:42
  3. Can QHash::capacity() be smaller than QHash::size()?!?
    By iw2nhl in forum Qt Programming
    Replies: 2
    Last Post: 24th August 2007, 01:17
  4. Iterate the QListWidget
    By vishal.chauhan in forum Newbie
    Replies: 1
    Last Post: 26th February 2007, 07:51
  5. How to iterate through QButtonGroup's buttons?
    By gadnio in forum Qt Programming
    Replies: 8
    Last Post: 13th January 2006, 05:06

Tags for this Thread

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.