Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6687195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:15:36+00:00 2026-05-26T05:15:36+00:00

How do I find out if a file is a photo or a video

  • 0

How do I find out if a file is a photo or a video in Qt?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:15:36+00:00Added an answer on May 26, 2026 at 5:15 am

    You ask if Qt can tell if something is “a photo or a video”, which is ambiguous, but I’ll translate it to:

    If I have a filename, does Qt have a feature to tell me if that is (a) an image file, (b) a video file, or (c) some other kind of file?

    Knowing a file’s type can come from a few sources. There’s the extension in the file’s name, there’s “sniffing” the contents of the file’s data and looking for recognized magic header sequences, and there’s random metadata which may live somewhere else that’s very specific to the applications or OS managing the file.

    Someone asked a question which was how to get the “MIME type” of a file in Qt:

    Find out the mime type and associated applications with Qt

    If you could do that, you could see if the string you got back was in the image/ hierarchy:

    http://en.wikipedia.org/wiki/Internet_media_type#Type_image

    But there’s no Qt functions for that. So you’re left pretty much checking the file extension, or if you specifically want to know if a given file is an image format that Qt can read, then you can use QImageReader::imageFormat() to “sniff” a file:

    QByteArray imageFormat = QImageReader::imageFormat(fileName);
    

    If the image is in the set of image types that Qt considers loadable, it will hand back a string of bytes that corresponds to that format. Otherwise you’ll get an empty string. That isn’t to say that failing this test means something isn’t an image of some other kind, of course.

    As for determining if something is a video file that Qt can play, there seems to be a possibility to do a similar “sniff” of video files if you’re using Phonon via MediaSource::type() and checking to see that it’s not Phonon::MediaSource::Invalid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a way to find out what file and line number
How do I find out if the file is not present or the access
Is there a way to find out from .a file what version of glibc
How do I programmatically find out the details of particular file from its meta-data.
How can I find out the name of the fields in a PDF file
Where could I find out the content type for a specific file format/extension? For
I want to find out if a file has been modified since the last
Is there any way to find out the file system format of a disk
There must be a way to find out who checked out the file directly
I'm following this guide here: http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html Every time I run: $ [ -f /etc/passwd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.