Qt6 comparing "\\" to QChar not working anymore
-
Hi,
I'm in the process of upgrading old code from Qt 5.13 to 6.6. We have code like this:
QString str = "12345"; if (str.at(0) == "\\") { // some code }The comparison used to work in Qt5, but not in Qt6. Looks like it sees the "\" as two chars instead of one escaped char, which it can't convert to QChar.
Changing it to (str.at(0) == QString("\").at(0)) works, but it seems a bit redundant. Is there a better way to get this working, or am I missing something?
-
Hi,
I'm in the process of upgrading old code from Qt 5.13 to 6.6. We have code like this:
QString str = "12345"; if (str.at(0) == "\\") { // some code }The comparison used to work in Qt5, but not in Qt6. Looks like it sees the "\" as two chars instead of one escaped char, which it can't convert to QChar.
Changing it to (str.at(0) == QString("\").at(0)) works, but it seems a bit redundant. Is there a better way to get this working, or am I missing something?
@clombard said in Qt6 comparing "\\" to QChar not working anymore:
"\"
This is a string. Comparing a string to a char is wrong. It worked because in Qt5 the QChar was implicitly converted to a QString. So use a char instead a string -->
'\\' -
@clombard said in Qt6 comparing "\\" to QChar not working anymore:
"\"
This is a string. Comparing a string to a char is wrong. It worked because in Qt5 the QChar was implicitly converted to a QString. So use a char instead a string -->
'\\'@Christian-Ehrlicher
Thanks! That solved it