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. Changing the character set to UTF-8
Forum Updated to NodeBB v4.3 + New Features

Changing the character set to UTF-8

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 205 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.
  • R Offline
    R Offline
    rovtar
    wrote on last edited by
    #1

    So what I'm trying to do is to read some text from a .txt file and I have letters like č,š,ž so I need the UTF-8 charset but I can't seem to find a way to do it. Here's the code where I'm reading from a file and creating a string. Can someone please help me out.

    QString temp_str;
        QFile file("strategije.txt"));
        if (file.exists()){
            if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
                QTextStream txtStream(&file);
                txtStream.seek(0);
                temp_str = txtStream.readLine();
                if(temp_str=="Situacija"){
                    temp_str = "";
                    for(int i=0; i<5; i++){
                        temp_str += txtStream.readLine();
                        temp_str += "\n";
                    }
                }
            }
            else{
                qDebug() << "the file is not open";
            }
        }
        else{
            qDebug() << "the file does not exist";
        }
        file.close();
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      See QTextStream::setCodec().

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rovtar
        wrote on last edited by rovtar
        #3

        Oh, that was simple. Thank you for the help @CHRISTIAN EHRLICHER, this worked.

        1 Reply Last reply
        1

        • Login

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