Important: Please read the Qt Code of Conduct -

[SOLVED] Character encoding

  • Hello, I am trying to read a text file using QTextStream and write lines into QListWidget... It can't read letters such as Č Ž Đ -> Croatian language... I tried to set codec but does not work... It always make some xy letters instead of Č Ž Đ...

    @QTextStream textStream(&test);
    How can I set encoding properly???

  • This might be an obvious question, but are you sure the source text is in fact in that encoding?

    What if you try setting your text editor (if possible) to Windows-1252 encoding and open the file there, does it look OK then?

  • Actually if I open that file with Notepad++ (its playlist.m3u) file then it shows Encode ANSI... ANSI encoding is a slightly generic term used to refer to the standard code page on a system, usually Windows. It is more properly referred to as Windows-1252

    I also set QtCreator to Windows-1252 but its same...

  • Hello again... I figured out it is not problem with QTextStream but with playlist->load() function... I does not load songs that with Ž Č Š letters...

    This line is causing problems... Song name is written correctly in .m3u file, but playlist won't load songs with Ž Č Š letters properly...
    @playlist->load(QUrl::fromLocalFile(saveloadPlaylist), "m3u")@

    Can I somehow set encoding for playlist???

  • Solved with following code...

    @QFile readm3u(saveloadPlaylist);
    QTextStream textStream(&readm3u);
    QString m3uPath = textStream.readLine();
    int m3uPathLenght = m3uPath.length() - 8;
    QString mediaPath = m3uPath.right(m3uPathLenght);

Log in to reply