Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt6 comparing "\\" to QChar not working anymore
Qt 6.11 is out! See what's new in the release blog

Qt6 comparing "\\" to QChar not working anymore

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 555 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clombard
    wrote on last edited by
    #1

    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?

    Christian EhrlicherC 1 Reply Last reply
    0
    • C clombard

      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?

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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 --> '\\'

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      C 1 Reply Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        @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 --> '\\'

        C Offline
        C Offline
        clombard
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        Thanks! That solved it

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved