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. [Solved] Read special characters from a csv-file
Forum Updated to NodeBB v4.3 + New Features

[Solved] Read special characters from a csv-file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.6k 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.
  • W Offline
    W Offline
    Woody
    wrote on 9 Aug 2012, 07:23 last edited by
    #1

    Hi

    I've got a problem with reading content from a file. And since I can't find any decent solution on the interwebs, I though I asked it here.

    My file contains special characters like Š. But when I do a readLine() on my file it returns something strange.

    In the file: 'Roman';'Šebrle'
    In my QString line: 'Roman';'Šebrle'
    And when I want to insert it in my database: UPDATE athletes SET lastname = '?ebrle', middlename = '', firstname = 'Roman'...

    So can anyone help me with this? How to get that Š?

    Thanks in advance!

    File not found. Nobody leave the room!

    1 Reply Last reply
    1
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 9 Aug 2012, 07:54 last edited by
      #2

      When using the QFile.readLine you will store data in a char buffer. This is a 8 bits variable only capable of holding ASCII values. The special characters are available when using the QTextStream to read/write data to the file.
      With the QTextCodec class you are able to transform into all kind of character sets. Even automatic detection of the best fitted text codec is possible.
      So it could be more like this:
      @
      if (file.open())
      {
      QTextStream in(file);
      QStringList inputStrings;

      in.setAutoDetectUnicode (true);
      while (!in.atEnd())
      {
      in >> inputStrings.append();
      }
      }
      @
      Don't have my Qt with me, so no idea if the in>>inputStrings.append() will work!
      Good luck with the coding!

      Greetz, Jeroen

      1 Reply Last reply
      1
      • W Offline
        W Offline
        Woody
        wrote on 9 Aug 2012, 08:33 last edited by
        #3

        But can it read line by line? Cause that has to stay.

        I just tried it. But i don't think it's a good solution. Cause I have to look for spaces myself.

        It solves my special character problem though.

        File not found. Nobody leave the room!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on 9 Aug 2012, 08:45 last edited by
          #4

          Read the Qt documentation:
          http://qt-project.org/doc/qt-4.8/qtextstream.html#readLine

          What do you mean with "look for spaces myself"?
          @QStringList spaceSeparatedStrings = singleString.split(" ");@
          ?

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Woody
            wrote on 9 Aug 2012, 09:07 last edited by
            #5

            It seperates on spaces.

            But thanks. That I didn't think of that myself!
            Quiet stupid :)
            Thanks for the reply guys. I think it works just fine now.

            File not found. Nobody leave the room!

            1 Reply Last reply
            0

            1/5

            9 Aug 2012, 07:23

            • Login

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