Q
Q
qvlad2012-05-03 19:08:12
Qt
qvlad, 2012-05-03 19:08:12

IndexOf bug or misuse?

Here is the code:

QString fakePath="c:/test/test.mp3";
int pos = fakePath.indexOf(QString("."),-1);
qDebug("pos=%d\n",pos);

Here is what is written in the documentation:
If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

The result is always -1. Who knows what's the matter?
Tested on Qt 4.8.0 Qt 4.7.4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
adminimus, 2012-05-03
@qvlad

indexOf searches for an occurrence starting at the position specified by the second argument. She is always looking forward, i.e. to the right. Because you set the initial position to -1, then it will search starting from the character "3" and further to the right. Naturally, there is no point there and the function will rightly return -1 (not found).
And what, in fact, did you expect the result with such arguments?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question