使用Qt检查字符串是否是有效的文件名 [英] Check whether a string is a valid filename with Qt

查看:625
本文介绍了使用Qt检查字符串是否是有效的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以用Qt 4.6检查给定的QString在当前操作系统上是否为有效的文件名(或目录名)?我想检查名称是否有效,不是文件是否存在.

Is there a way with Qt 4.6 to check if a given QString is a valid filename (or directory name) on the current operating system ? I want to check for the name to be valid, not for the file to exist.

示例:

// Some valid names
test
under_score
.dotted-name

// Some specific names
colon:name // valid under UNIX OSes, but not on Windows
what? // valid under UNIX OSes, but still not on Windows

我将如何实现呢?有一些Qt内置函数吗?

How would I achieve this ? Is there some Qt built-in function ?

我想避免创建一个空文件,但是如果没有其他可靠的方法,我仍然想看看如何以一种干净"的方式来做.

I'd like to avoid creating an empty file, but if there is no other reliable way, I would still like to see how to do it in a "clean" way.

非常感谢.

推荐答案

我不认为Qt具有内置功能,但是如果使用Boost,则可以使用Boost.Filesystem的

I don't think that Qt has a built-in function, but if Boost is an option, you can use Boost.Filesystem's name_check functions.

如果不能使用Boost,则其关于name_check功能的页面仍然是在各种平台上要检查的内容的很好概述.

If Boost isn't an option, its page on name_check functions is still a good overview of what to check for on various platforms.

这篇关于使用Qt检查字符串是否是有效的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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