How to know if a file is a text file or a binary file?

I want to search a string in all text files in a directory. Encoding could be either ASCII or UTF8. there is no convention in naming. for example a c++ source file could be named like 'a.jpg'. before trying the 'file' command of unix-like systems I want to know if there is a Qt way for this? or maybe cross-platform?...

What you could do is start looking for the text, and stop when you either find that text, or find something that is not text, and do that for all files. Exactly what you want to consider as not text depends on possible text encodings of course, but if you are limited to ASCII and UTF8, it might not be too difficult.