Results 1 to 3 of 3

Thread: How to know file type

  1. #1
    Join Date
    Sep 2008
    Posts
    58
    Thanks
    11
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Exclamation How to know file type

    Hi,

    How to know what's the file type in qt. I am using following method to know the file type.
    Qt Code:
    1. QString fileName("/home/nirav/oneStar.jpg");
    2.  
    3. if(fileName.endsWith(".jpg",Qt::CaseSensitive);
    4. qDebug()<< "File type is jpg" ;
    5. else
    6. qDebug()<< "File unknow" ;
    To copy to clipboard, switch view to plain text mode 

    But if image file only contains name(i.e oneStar), how to know that file is of Image type.
    I have checked QDir,QFile,QFileinfo but no one provides file type, it can only differentiate File or Directory or System link.

    can anybody suggest me the right way to find the file type.

    You suggestion would be great help for me.

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to know file type

    Do not expect Qt to know every possible file type.
    If it's some kind of bitmap you can use QImage or QPixmap to load the file without specifying the format - in that case the loader will try to guess the format by reading the file header and return appropriate value if there's a problem to determine it.

    Edit:
    Forgot to mention that after opening the file you can use for example
    QImage::format().

    Edit2:
    Actually maybe QImageReader::format() would be better
    Last edited by calhal; 16th December 2009 at 14:29.
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to know file type

    Linux attempts to know as many file types as possible, you can use the Linux MIME system to detect the type. On Windows you are stuck with the file extension unless you open the files yourself and detect from a signature.

Similar Threads

  1. Replies: 5
    Last Post: 5th August 2009, 18:32
  2. getting a file extenstion list from a MIME type
    By roxton in forum Qt Programming
    Replies: 0
    Last Post: 10th April 2009, 19:27
  3. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 14:43
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 20th July 2007, 00:38
  5. Associating icon with a file type
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2006, 17:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.