PDA

View Full Version : Get string buy its number



TJSonic
2nd November 2010, 01:53
Ok i need something like database but small. For examle i have 5 strings which have their own uniq id.
And if request id it must give me a string wich connected with this id.

Somethin like:
list->addVar(1,"blah1');
list->addVar(5,"blah2");

list->requeststring(5); and it returns "blah2"

and if we have added list->addVar(5,"blah2"); one time and then another time like
list->addVar(5,"blah3"); it will replace old "blah2" with new "blah3" string

so what object must i use in this case??

Timoteo
2nd November 2010, 02:06
Tried QMap<int, QString> or std::map<int, string>?

poporacer
2nd November 2010, 02:08
If it is small, then maybe an array would be the way to go!

TJSonic
2nd November 2010, 14:24
I have read abowt QMap and it is exactly what i want)

But here is a problem:



void MainWindow::textChanged(QString textch)
{
//At first we are finding index of our element
int lineidx = tabWidget->currentIndex();
//Then adding item in QMap using lineidx varieble as key and textch as value (maybe i do something wrong because after qDebug()<< linemap.value(index); it returns nothing!
linemap[lineidx]= textch;
}


What wrong??

tbscope
2nd November 2010, 14:42
in:
linemap.value(index)

does index exist in the map?

TJSonic
2nd November 2010, 14:48
Index is an variable which must exist in map if linemap[lineidx]= textch; is right way to add value in map)