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. Extract QChar from QByteArray
Qt 6.11 is out! See what's new in the release blog

Extract QChar from QByteArray

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.8k Views 1 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.
  • H Offline
    H Offline
    harveyab
    wrote on last edited by
    #1

    I have an iterator and for loop scanning a QByteArray.
    I want to check for a valid UTF-8 character and extract it as a QChar at the current iterator position.
    How do I do that?
    Thanks.

    1 Reply Last reply
    1
    • M Offline
      M Offline
      marceloarguello700
      wrote on last edited by
      #2

      Look this page will help you
      http://www.instructables.com/id/Programming--how-to-detect-and-read-UTF-8-charact/step5/How-are-UTF-8-encoded-Unicode-characters-/

      Greetings

      H 1 Reply Last reply
      0
      • M marceloarguello700

        Look this page will help you
        http://www.instructables.com/id/Programming--how-to-detect-and-read-UTF-8-charact/step5/How-are-UTF-8-encoded-Unicode-characters-/

        Greetings

        H Offline
        H Offline
        harveyab
        wrote on last edited by harveyab
        #3

        @marceloarguello700 Sorry I didn't make it clear. I know what I would need to do it myself in code. I wondered if there was a function or member function to do it in one code statement. I would think this happens all the time, and I don't want to "re-invent the wheel."

        Perhaps I should not have said UTF-8. I just want to "get" the QChar at the current position of the QByteArray. How do I access a possibly multibyte QChar from a QByteArray?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ravi Sankar
          wrote on last edited by
          #4

          I know my reply is for old post,but this will helpfull for new people.

          Below is the example code to filter UTF-8.I hope you will get resolution for your problem.

          bool istextprintable(QByteArray text_temp){

          QChar chrtr;
          for(int i = 1; i < text_temp.size(); i++) {
          chrtr = text_temp.at(i);
          if((chrtr.isDigit() || chrtr.isLower() || chrtr.isUpper() || chrtr.unicode() == 0 || chrtr.unicode() == 32) == 0 ){
          
              return 0;
              }
          }
          return 1;
          

          }

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            Untested

            (as QDataStream might search for a special header)

            // QByteArray byteArray;
            QDataStream stream(byteArray);
            QChar tempChar;
            stream >> tempChar;
            

            "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
            0

            • Login

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