View Full Version : Convertion from Qstring to int

27th August 2014, 10:48
I have a Qstring ORBString = "nFeatures=2000, scaleFactor=1.2, nLevels=8, EdgeThreshold=31, Firstlevel=0, WTA_K=2, ScoreType=0 , PatchSize=31";
Then I use QstringList ORBLists = ORBString.split(",", QString::SkipEmptyParts);
bool ok;
int nFeatures = ORBLists.at(0).toInt(&ok,10); // it gives only 0 not 2000

27th August 2014, 10:55
"nFeatures=2000" is definitely not a number so trying to convert it to int will yield 0 and will raise the error flag (your "ok" variable will be set to false).

27th August 2014, 10:57
...and "ok" is set to false as I guess, becaue you can't convert "nFeatures=2000" to int. You can convert "2000" to int, so you have to extract this number from this string (use another split() or mid() or whatever function you find most convenient to you) and then, when you have string "2000", call toInt() on it.