How to get File Header Infos? SOLVED
-
Hi, all,
is there a way in Qt, to get file infos like the linux-comand "file" gives?
For example, when I type in my shell
"file abc.dd" I get the result "abc.dd: SQLite 3.x database"And now I want to do the same using Qt...
thanks in advance,
Viktor -
Well, you can use "QProcess":http://qt-project.org/doc/qt-5.0/qtcore/qprocess.html inside Qt to launch the linux-command file and then recover the output.
Example:
@QString program = "/usr/bin/file";
QStringList arguments;
arguments << "/home/myfile.txt";QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);if (!myProcess.waitForFinished())
return false;QByteArray result = myProcess.readAll();@
-
thanks for your peply, I found an easier way: read the magic Number, which defines the file type, with QStream.
Example:
@QFile filetest(fileName); //fileName is a result of an openfile-dialog
filetest.open(QIODevice::ReadOnly);
QDataStream in(&filetest);
qint32 magicNumber;
in >> magicNumber;@now "magicNumber" contains the value for, in my example, sqlite-files...
thanks anyway!