[Qt-interest] problem with accents
Andre Somers
andre at familiesomers.nl
Tue Aug 4 08:10:36 CEST 2009
mierdatutis mi wrote:
> Yes, I know the file encoding is:
>
>
> file: UTF-8 Unicode text
>
> 2009/8/4 Andre Somers <andre at familiesomers.nl
> <mailto:andre at familiesomers.nl>>
>
> Hi,
>
> I would use QTextStream. It can do all the nasty coding/decoding
> for you.
> Do you know the encoding for your textfile? If not, find out. You
> will need it to set the correct codec, no matter what way you end
> up using.
>
>
> > No, I don't use QtextStream. I do:
> >
> > while (!file.atEnd()) {
> >
> > QTableWidgetItem *item = new QTableWidgetItem;
> >
> > QByteArray line = file.readLine();
> >
> > item->setText(line);
> >
> > tabla->setItem(b,0,item);
> >
> > tabla->setRowHeight(b,20);
> >
> > b++;
> >
> > }
> >
>
>
So, change the above to using QTextStream:
QTextStream in(&file);
in.setCodec("UTF-8");
while (!in.atEnd()) {
QTableWidgetItem *item = new QTableWidgetItem;
QString line = in.readLine();
item->setText(line);
tabla->setItem(b,0,item);
...
}
Note: code above is untested.Take it as pseudo-code ;-)
Good luck!
André
More information about the Qt-interest-old
mailing list