QTextStream - problem reading accented - special chars
-
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 bambiniNL - Bak, Bert
dal 27.07.2013 al 03.08.2013 2 adulti, 2 bambiniDE - 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 bambiniNL - Bak, Bert
dal 27.07.2013 al 03.08.2013 2 adulti, 2 bambiniDE - 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 guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = PoggioBlumen_Mail2
TEMPLATE = appSOURCES += main.cpp
mainwindow.cpp
blumen_mail_cl.cpp
prenotazione_cl.cppHEADERS += mainwindow.h
blumen_mail_cl.h
prenotazione_cl.hFORMS += 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..... :-( -
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.
-
Hi, which encoding your target text file is used?