Reading file with QTextStream looping over file
-
wrote on 17 Aug 2012, 08:21 last edited by
If you expect to have unicode characters why don't you set codec to one of the utf's? Try "setting codec":http://qt-project.org/doc/qt-4.8/qtextstream.html#setCodec for your QTextStream object to UTF-8. Unless you set one globally before...
-
wrote on 17 Aug 2012, 08:26 last edited by
Can you send me your file 'as is'.
-
wrote on 17 Aug 2012, 08:28 last edited by
That doesn't help with the fact I don't have to use a QTextStream. I think (read: I'm quiet sure) that the problem has to do with the QTextStream. But where that is, I really haven't got a clue.
Edit: I can't really send you the file, sorry. But there isn't really something wrong with the line, nor the file itself.
-
wrote on 17 Aug 2012, 08:44 last edited by
Ok, maybe, you may post which special characters appear in the file?
-
wrote on 17 Aug 2012, 08:51 last edited by
In this file the only special characters are ë (on Daniël, Joëlle, ...), é (on Conté, Romanée, ...), ö (on Buddenböhmer), ü (on Büller)
But none of these characters are on line 153, 154, 155, 156
-
wrote on 17 Aug 2012, 09:05 last edited by
Does this:
@
while(true)
qDebug() << in.readLine();
@read past that magic line 154?
Have you validated the strings that readLine returns? Maybe 154 is actually the last line in the file because some apparent multiple lines in the file are read joined together (for whatever crazy unicode reason).bq. I tried it with 2 files, one where he got to 87% and one to 65%
I suppose the other file was also such a name list with that (maybe broken) unicode encoding. Do the following:
Open a text editor and type by hand some lines that reproduce the visual appearance (i.e. which characters come when) in one of the unicode files. This is to make sure there aren't any strange unicode characters inside. Then either compare them in a hex editor or just try to read that hand-crafted file (maybe multiply the lines by copy-pasting to 200 or so).
Now that should absolutely work, because your code is very simple. And if it does, you know that the original files contain crazy unicode control characters that need to be rectified first. It may be an effect due to the automatic unicode detection. If it's not detected correctly, who knows what happens. Why don't you set the codec yourself as proposed already? -
wrote on 17 Aug 2012, 09:10 last edited by
Do you sure the file is really unicode? It seems you have ASCII file that detected by QTextCodec as UTF-8.
-
wrote on 17 Aug 2012, 09:33 last edited by
I don't think my decoding is the problem here.
If I don't try to decode it, it does exactly the same as with the autoDetect and the setCodec("utf-8").I'll try to write some of it again, but that's not a solution for 30k lines-file :)
-
wrote on 17 Aug 2012, 09:49 last edited by
Going to update Qt, I know have 4.7.4, my colleague has 4.8.2.
And on his PC it works fine. -
wrote on 17 Aug 2012, 10:10 last edited by
It seems you may have been affected by bug "QTBUG-9814":https://bugreports.qt-project.org/browse/QTBUG-9814.
-
wrote on 17 Aug 2012, 11:10 last edited by
Mmh that indeed could be possible. Thnx for the tip!
-
wrote on 20 Aug 2012, 06:36 last edited by
It is 'solved'. I installed Qt 4.8.2 and it does it's job just fine. Takes the whole file and treats every line properly.
I don't think I need to put [SOLVED] in the title cause the problem in 4.7.4 isn't solved.
15/17