Comparison of QChars
-
Hi guys,
sry for this nooby question, but i am trying to compare a QChar out of a QString with a simple char and i dont get it.I have simply a line of numbers and want to seperate it where a ":" is.
For example 315:15 -> x=315 , y=15here is my code
QString part1=""; QString part2=""; bool before; for(int y=0; y < line.size(); y++){ if( before && line.at(y)!=":")){ part1 += line.at(y); }else if(line.at(y)==":"){ before = false; }else if(!before && line.at(y)=""){ part2 += line.at(y); } }In this case i get the errror:
error: no match for 'operator==' (operand types are 'const QChar' and 'const char [2]')so i tried to cast the char, but it is still a QChar[2] . And i do not understand how a simple char can be a QChar array of 2.
So i tried:QChar seperator = (QChar)(":");Same problem. So what i am doing wrong here?
-
I think, the error in your code is here:
}else if(!before && line.at(y)=""){ part2 += line.at(y); }thats a typo, = needs to be a == for a valid if statement.
Anyway have you thought about useing
split(':')could make things simpler for you.
-
If I may -
split()is horrible. It creates a list of copies - really bad for performance. Please usesplitRef()when parsing data. It creates a vector of StringRefs, a much better solution if you don't need to copy the data (and you don't need to here) and a much more cache friendy structure.