本文整理汇总了C++中QMimeDatabase::mimeTypesForFileName方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeDatabase::mimeTypesForFileName方法的具体用法?C++ QMimeDatabase::mimeTypesForFileName怎么用?C++ QMimeDatabase::mimeTypesForFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeDatabase
的用法示例。
在下文中一共展示了QMimeDatabase::mimeTypesForFileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filePickerType
QString QQnxFilePicker::filePickerType() const
{
bool images = false;
bool video = false;
bool music = false;
QMimeDatabase mimeDb;
for (int i = 0; i < m_filters.count(); i++) {
QList<QMimeType> mimeTypes = mimeDb.mimeTypesForFileName(m_filters.at(i));
if (mimeTypes.isEmpty())
return QStringLiteral("Other");
if (mimeTypes.first().name().startsWith(QLatin1String("image")))
images = true;
else if (mimeTypes.first().name().startsWith(QLatin1String("audio")))
music = true;
else if (mimeTypes.first().name().startsWith(QLatin1String("video")))
video = true;
else
return QStringLiteral("Other");
}
if (!video && !music)
return QStringLiteral("Picture");
if (!images && !music)
return QStringLiteral("Video");
if (!images && !video)
return QStringLiteral("Music");
return QStringLiteral("Other");
}
示例2: operator
HttpResponse StaticFileServer::operator()(const HttpRequest &req)
{
if(req.method() != HttpRequest::GET && req.method() != HttpRequest::HEAD)
return HttpResponse::MethodNotAllowed(QStringList() << "HEAD" << "GET");
if(_root.isEmpty())
return HttpResponse::NotFound();
QString path = QDir::cleanPath(_root + req.pathMatch().captured(1));
if(!path.startsWith(_root))
return HttpResponse::NotFound();
if(QFileInfo(path).isDir())
path.append("/index.html");
QFile file(path);
if(!file.open(QFile::ReadOnly)) {
logger::warning() << path << file.errorString();
return HttpResponse::NotFound();
}
// TODO handle HEAD type request
HttpResponse resp(200);
QMimeDatabase mimedb;
QList<QMimeType> mimetypes = mimedb.mimeTypesForFileName(path);
if(mimetypes.isEmpty())
resp.setHeader("Content-Type", "application/octet-stream");
else
resp.setHeader("Content-Type", mimetypes.first().name());
if(req.method() == HttpRequest::GET)
resp.setBody(file.readAll());
else
resp.setHeader("Content-Length", QString::number(file.size()));
file.close();
return resp;
}