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. How to convert QString to ASCII ?
Forum Updated to NodeBB v4.3 + New Features

How to convert QString to ASCII ?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 3.0k Views 2 Watching
  • 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    I need something like this:
    if ( "a" == "b" -1 ) ......
    ASCII:
    if ( 97 == 98 - 1 ) ......

    https://github.com/sonichy

    raven-worxR VRoninV 2 Replies Last reply
    0
    • sonichyS sonichy

      I need something like this:
      if ( "a" == "b" -1 ) ......
      ASCII:
      if ( 97 == 98 - 1 ) ......

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @sonichy
      see QChar::toLatin1() which returns a char which also can be cast to an int
      to get the QChar, use QString::at()

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      sonichyS 1 Reply Last reply
      6
      • sonichyS sonichy

        I need something like this:
        if ( "a" == "b" -1 ) ......
        ASCII:
        if ( 97 == 98 - 1 ) ......

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @sonichy said in How to convert QString to ASCII ?:

        I need something like this:
        if ( "a" == "b" -1 ) ......

        Use single quotes instead of double quotes: if ( 'a' == 'b' -1 ) this is pure C++, nothing Qt specific

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        5
        • raven-worxR raven-worx

          @sonichy
          see QChar::toLatin1() which returns a char which also can be cast to an int
          to get the QChar, use QString::at()

          sonichyS Offline
          sonichyS Offline
          sonichy
          wrote on last edited by
          #4

          @raven-worx said in How to convert QString to ASCII ?:

          cast to an int

          QString a = ...;
          QString b = ...;
          ushort as = a.at(0).unicode();
          ushort bs = b.at(0).unicode();
          qDebug() << a << as << b << bs;
          if(as != bs-1) return false;
          

          https://github.com/sonichy

          kshegunovK 1 Reply Last reply
          0
          • sonichyS sonichy

            @raven-worx said in How to convert QString to ASCII ?:

            cast to an int

            QString a = ...;
            QString b = ...;
            ushort as = a.at(0).unicode();
            ushort bs = b.at(0).unicode();
            qDebug() << a << as << b << bs;
            if(as != bs-1) return false;
            
            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5
            QByteArray a_ascii = a.toLatin1();
            

            Read and abide by the Qt Code of Conduct

            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