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] Character encoding
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Character encoding

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.6k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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);
    textStream.setCodec("Windows-1252");
    @
    How can I set encoding properly???

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Apelsinsaft
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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???

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Solved with following code...

            @QFile readm3u(saveloadPlaylist);
            if(readm3u.open(QIODevice::ReadOnly))
            {
            QTextStream textStream(&readm3u);
            while(!textStream.atEnd())
            {
            QString m3uPath = textStream.readLine();
            int m3uPathLenght = m3uPath.length() - 8;
            QString mediaPath = m3uPath.right(m3uPathLenght);
            content.push_back(QUrl::fromLocalFile(mediaPath));
            }
            readm3u.close();
            playlist->addMedia(content);
            }@

            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