使用Qt查找mime类型和相关的应用程序 [英] Find out the mime type and associated applications with Qt

查看:466
本文介绍了使用Qt查找mime类型和相关的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找出给定档案的MIME类型或内容类型?
我不能使用后缀,因为文件可以重命名。

How can I find out a mime-type or content-type of a given file? I cannot use the suffix because the file could be renamed.

可能的补充将它们分类为jpg,gif,png等是图像文件,

Possible additions would be categorizing them as jpg, gif, png and so on are image files and can be opened by editing applications, which has been set in the OS.

提前感谢。

推荐答案

什么平台?在* nix上,应该参考程序文件是如何实现的,这是基于一些启发式方法,包括检查文件的前几个字节(许多文件格式开始

What platform? On *nix, you should refer to how the program file does it, which is based on a few heuristics including checks of the first few bytes of a file (many file formats start with a fixed header, including many image formats).

如果您使用的是Windows操作系统,那么* nix 文件命令可能仍然是有启发性的,即使你不能直接重用它的代码。在Windows API中也可能有一些更好的解决方案(我不是Windows程序员)。

If you're on Windows, the *nix file command is probably still instructive, even if you can't reuse its code as directly. There may also be some better solution in the Windows APIs (I'm not a Windows programmer).

这篇关于使用Qt查找mime类型和相关的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆