[Qt-interest] How to check between "Text" and "Non-Text" File

Andre Somers andre at familiesomers.nl
Tue Apr 20 10:10:59 CEST 2010


On 20-4-2010 9:54, yogesh upreti wrote:
> Hallo Group,
> Can someone have any idea how to check between "Text" and "Non-Text" File?
> I am making an application, which gives a preview of files depending 
> on type, i.e. if the file is a image, is shows a preview, if file is 
> Text it should show top 10 lines in a text edit.
> I am able to recognise image file with extension, because normally in 
> all the system it is like that, but I am not able to recognise Text 
> files (as they can have any extension and some times no extension). I 
> have to differentiate them with Binary data files (because when I 
> start reading them my programme gets hang, or shows Garbage in text edit)
> Can someone tell me how to recognise that?
>
There is no reliable way to do that. But you may be able to use some 
heuristics. One such a heuristic may be that at least for English text, 
you probably don't expect byte values over 126 in your file.

André



More information about the Qt-interest-old mailing list