PDA

View Full Version : QRegExp



szczav
19th June 2007, 17:01
Hi!

I have QStringList genreItems which is list of music genres. I want to find index of genre "Rock", but I get other genre witch got "rock" in its name (Classical Rock), but witch is before Rock genre.
What should I do to find only element of list which is the same, not similar to my string?



QRegExp rx(my_genre);
int genrePosition = genreItems.indexOf(rx);

croland
19th June 2007, 18:52
Can you try:


int genrePosition = genreItems.indexOf("Rock");

jacek
19th June 2007, 18:56
Try:
QRegExp rx( "^" + my_genre + "$" );
...
Although according to the docs it shouldn't be necessary. Which Qt version do you use?

Gopala Krishna
19th June 2007, 18:59
I second croland if what you want exact match i.e

int genrePosition = genreItems.indexOf(my_genre);

szczav
19th June 2007, 20:07
All works fine :/ I missed that my parameter in QRegExp constructor has wrong value.
Lot of work to do and not much sleep...eh...
Sorry for trouble guys and thanks for help!