Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Extract QChar from QByteArray

    General and Desktop
    4
    5
    2371
    Loading More Posts
    • 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
      harveyab last edited by

      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 Reply Quote 1
      • M
        marceloarguello700 last edited by

        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 Reply Quote 0
        • H
          harveyab @marceloarguello700 last edited by harveyab

          @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 Reply Quote 0
          • R
            Ravi Sankar last edited by

            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 Reply Quote 0
            • VRonin
              VRonin last edited by

              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 Reply Quote 0
              • First post
                Last post