Results 1 to 3 of 3

Thread: Initializing a QList of QHashes

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Initializing a QList of QHashes

    Hello!

    I want to use a data structure made from a QList that has QHashes as elements. Here is the declaration:

    QList< QHash<QString, float> > data;

    With this I get an empty list that I want to fill while reading a file line by line. Now I don't know how to get the QHashes into the QList. I don't want to preallocate them on the heap, because I don't know how many of them I need and because it would be more convenient, if I don't have to destroy them. The whole data structure should be automatically destroyed, when the QList goes out of scope. I'm probably just missing the right syntax here. Can anyone help?

    Thanks
    Cruz

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Initializing a QList of QHashes

    did you try something like this?
    Qt Code:
    1. void FileProcessor::processFile()
    2. {
    3. QList< QHash<QString, float> > data;
    4. ...
    5. while (!file.atEnd()) {
    6. ...
    7. data << processLine(file.readLine());
    8. ...
    9. }
    10. ...
    11. }
    12.  
    13. QHash<QString, float> FileProcessor::processLine(const QString &line)
    14. {
    15. QHash<QString, float> res;
    16. //parse the line and fill the hash
    17. return res;
    18. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Cruz (24th November 2009)

  4. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Initializing a QList of QHashes

    Yes it works, thanks!

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55
  2. QList, copy problems
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 5th February 2010, 00:06
  3. Return value to QList
    By lyucs in forum Newbie
    Replies: 7
    Last Post: 16th October 2009, 02:31
  4. Regarding the implementation of QList
    By rachit.gupta in forum Qt Tools
    Replies: 1
    Last Post: 23rd September 2009, 12:41
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

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.