Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get File Header Infos? SOLVED
Qt 6.11 is out! See what's new in the release blog

How to get File Header Infos? SOLVED

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vittorio
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Seba84
      wrote on last edited by
      #2

      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();@

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vittorio
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved