Qt6 QString[] QChar compare with char
-
Hey
Say I have something like this...QString te("dcfsacsa") te[0] == "#"
What is the proper way of doing it under Qt6 as atm it just errors out with
error C2678: binary '==': no operator found which takes a left-hand operand of type 'QChar' (or there is no acceptable conversion)
-
@Dariusz said in Qt6 QString[] QChar compare with char:
te[0] == "#"
I know nothing about Qt6, or whether there is something special there. However, I think you have mistyped.
te[0]
isQChar
, but you are comparing against"#"
, which is a (literal) string, not a char. I think you intendedif (te[0] == '#') ...
-
@Dariusz said in Qt6 QString[] QChar compare with char:
te[0] == "#"
I know nothing about Qt6, or whether there is something special there. However, I think you have mistyped.
te[0]
isQChar
, but you are comparing against"#"
, which is a (literal) string, not a char. I think you intendedif (te[0] == '#') ...
-
if you want to get singal character from your string
then you can useQString::at()
it return the character from your string at particular index.Try This
QString te("dcfsacsa"); if(te.at(0) == '#') { /// Your Code } else { /// Your Code }
-
Also I cant do QString[0] == QChar("#") because there is apparently no constructor for it?
Did you read what I wrote above? I told you why your
"#"
won't work. It's a good idea to read and act on answers rather than ignoring them....