Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QTextStream - problem reading accented - special chars
Forum Updated to NodeBB v4.3 + New Features

QTextStream - problem reading accented - special chars

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 2.0k 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.
  • F Offline
    F Offline
    fox1969
    wrote on last edited by
    #1

    Goodnight to all from north of italy, from LUG Govonis Finale Ligure.

    I'm using a Debian Testing with Qt Creator 2.8.1Based on Qt 5.1.1 (GCC 4.6.1, 64 bit)

    I made a regex for hotel booking for parsing mail (strings) of this type:

    @PL - Krasinska, Katarzyna
    dal 16.07.2013 al 27.07.2013 2 adulti, 3 bambini

    NL - Bak, Bert
    dal 27.07.2013 al 03.08.2013 2 adulti, 2 bambini

    DE - Großmann, Heiko
    dal 03.08.2013 al 10.08.2013 2 adulti, 2 bambini@

    You can see there are particular characters like ß.
    I have to prepare a regex to retrieve name, surname, arrival...etc....
    I wrote a little function to read the file and tested the returned string with a TextEdit. The function goes on without compile errors but....i cant see the ß char.
    In this case i have only one but it can happens that...there are other chars, for example umlaut or other accented unicode chars.

    If i test the TextEdit with this:
    ui->textEdit->setText("Großmann");
    All function good but not with my text file.
    This is the code of reading function:

    @
    QString MainWindow::read(QString nome_file )
    {
    QFile mfile(nome_file);
    QTextStream in(&mfile);
    //in.setCodec("UTF-8");
    //in.setAutoDetectUnicode(true);
    mfile.open(QIODevice::ReadOnly | QIODevice::Text);
    QString data = in.readAll();
    return data;
    }
    @

    There are two lines commented but...if i don't comment them....all is the same.
    The returned variable is tested with this simple function;

    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    mail_str = MainWindow::read(file_name);
    
    ui->textEdit->setText(mail_str);
    

    }
    @

    This is the wrong output:

    @
    PL - Krasinska, Katarzyna
    dal 16.07.2013 al 27.07.2013 2 adulti, 3 bambini

    NL - Bak, Bert
    dal 27.07.2013 al 03.08.2013 2 adulti, 2 bambini

    DE - Gro=DFmann, Heiko
    dal 03.08.2013 al 10.08.2013 2 adulti, 2 bambini
    @

    This is my pro file, excuse me but i have no experience wit bq quotes so i use code quotes.
    @
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = PoggioBlumen_Mail2
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp
    blumen_mail_cl.cpp
    prenotazione_cl.cpp

    HEADERS += mainwindow.h
    blumen_mail_cl.h
    prenotazione_cl.h

    FORMS += mainwindow.ui

    @

    My EDITOR settings are:
    Default encoding : UTF-8
    UTF-8 BOM : Keep if already present.

    Tanks in advance! Before desturb you i spent several days with google to find a soluion but...nothing!
    I tried reading the file in a loop line by line but nothing changes..... :-(

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fox1969
      wrote on last edited by
      #2

      Any idea to solve my problem?

      I'm studying various tutorial on the web without finding anything and i'm sad to....change complitely IDE RAD only for some characters.....

      Before i used Visual C# on WIN without problems...now i want to migrate but it's not easy.

      Thanks and excuse me.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        Hi, which encoding your target text file is used?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fox1969
          wrote on last edited by
          #4

          if i use the command file from the linux console i have:
          MIME entity, ASCII text

          if i use file -i to check the mime i have:
          text/plain; charset=us-ascii

          Is this your question?

          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