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] QTextStream don't likes umlauts

[SOLVED] QTextStream don't likes umlauts

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.2k 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.
  • C Offline
    C Offline
    chimaira1988
    wrote on last edited by
    #1

    Hey,
    I try to write into a csv-file, which works perfectly for normal characters but it doesn't work with german umlauts. setCodec("UTF-8") worked for importing csv-files, seems to not fit here.

    Here is the code I using
    @
    QString filename = QFileDialog::getSaveFileName(0, "DialogTitle", "filename.csv", "CSV files (.csv);;Zip files (.zip, *.7z)", 0, 0);
    QFile data(filename);
    if(data.open(QFile::WriteOnly |QFile::Truncate |QFile::))
    {
    QTextStream output(&data);
    //output.setCodec("UTF-8");
    output << "ßäÄÖöÜü";
    }
    @
    maybe someone of you could give me a hint. :)

    Thanks in advance

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      setCodec sets encoding of the stream, not the input data. You pass your string as a const char* string literal which is "assumed to be Latin-1 encoded":http://qt-project.org/doc/qt-5/qtextstream.html#operator-lt-lt-16.
      You need to tell it what encoding it is really in.
      @output << QString::fromUtf8("ßäÄÖöÜü");
      //or just
      output << QString("ßäÄÖöÜü"); //this ctor assumes utf-8@
      In any case it's a bad idea to put national characters in source code.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chimaira1988
        wrote on last edited by
        #3

        Later it shouldn't really be in the code, It's just for testing. It's the input from the form which should take umlauts (streets in germany are called Straße; and so on...)

        I wasn't precise enough...my code snippet is only for testing and if I take the form input your solution will not work, wouldn't it?

        Edit: Problem solved

        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