PDA

View Full Version : qstringlist question



martial_arts_drummer
10th January 2011, 12:31
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

Lykurg
10th January 2011, 12:37
I don't know what you are really try the achieve, but the solution to what you ask is QHash or QMap.

high_flyer
10th January 2011, 12:42
Or just use to QStringLists - one for each file.

martial_arts_drummer
10th January 2011, 12:47
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.

high_flyer
10th January 2011, 13:04
You can use QMap (whic implement QHash) as Lykurg suggested, and you can map as many string to as many files as you want.


QMap<QString,QString> mapFoundStrings;
...
mapFoundStrings[strFileName1] = strFoundStr;