从 QFile 获取文件名?
例如:
QFile f("/home/umanga/Desktop/image.jpg");
我如何只获取文件名 - “image.jpg”?
eg:
QFile f("/home/umanga/Desktop/image.jpg");
How I get only the filename - "image.jpg"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
QFileInfo
删除路径(如果有):Use a
QFileInfo
to strip out the path (if any):一种方法,不一定是最好的:从
QFile
中,您可以使用QFile::fileName()
:那么你可以使用字符串功能,例如
QString::split
:One approach, not necessarily the best: from a
QFile
, you can get the file specification withQFile::fileName()
:then you can just use the string features like
QString::split
:另外:要分隔具有 QFile f 的文件名和文件路径,
您不需要创建额外的 fileInfo。
just in addition: to seperate filename and file path having
QFile f
you don't need to create an additional fileInfo.
我用这个:
I use this: