Results 1 to 5 of 5

Thread: qstringlist question

  1. #1
    Join Date
    Dec 2010
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qstringlist question

    ok, here is the situation...

    I am searching several files for specific strings.

    If found, I want to store in a QStringList.
    It is possible that my search does not return a valid string from File1
    and does return a valid string from File2.


    I want to store the strings in the QStringList location associated with the file.

    My_QStringList << found_search_string WILL NOT work because it may be stored
    in location 2 incorrectly.

    I need to
    My_QStringList[i] = found_search_string (where i is the file number)

    How is this accomplished? I am running into errors using:

    My_QStringList[i] = this_string and
    My_QStringList.at(i) = this_string.

    Any assistance would be appreciated.

    thanks

    John

  2. #2
    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: qstringlist question

    I don't know what you are really try the achieve, but the solution to what you ask is QHash or QMap.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qstringlist question

    Or just use to QStringLists - one for each file.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Dec 2010
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qstringlist question

    I don't think QHash will work.

    Lets say I am searching 4 files for "widget" and "widget" is found in 2 of the files.

    I want to display using QTableWidget a listing for all 4 files. If "widget" is not found, the field should be blank.

    if I use:
    My_QStringList << found_string .. I have no association to the file that this was found in because if "widget" is found in the second file, MyQStringList will store the
    value in the first location.

    I want to do:
    My_QStringList[2] = found_string.. This way, I will know that the found string is associated with the second file.

    Make Sense?


    thanks.

    John

    I created an array of QString which will suffice.
    But I figured there should be a way to store values into a specific location within QStringList.

    Oh Well.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qstringlist question

    You can use QMap (whic implement QHash) as Lykurg suggested, and you can map as many string to as many files as you want.
    Qt Code:
    1. QMap<QString,QString> mapFoundStrings;
    2. ...
    3. mapFoundStrings[strFileName1] = strFoundStr;
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Plz help me,I met a bug about QStringList
    By study_c in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2010, 15:56
  2. QList/QStringList comparison question
    By di_zou in forum Newbie
    Replies: 5
    Last Post: 28th October 2009, 14:35
  3. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  4. QStringList
    By dragon in forum Newbie
    Replies: 2
    Last Post: 8th June 2007, 17:26
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

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.