Important: Please read the Qt Code of Conduct -

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,

  • Well, you can use "QProcess": inside Qt to launch the linux-command file and then recover the output.

    @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.


    @QFile filetest(fileName); //fileName is a result of an openfile-dialog;
    QDataStream in(&filetest);
    qint32 magicNumber;
    in >> magicNumber;@

    now "magicNumber" contains the value for, in my example, sqlite-files...

    thanks anyway!

Log in to reply