在Qt中删除文件名的扩展名 [英] Removing extension of a file name in Qt

查看:1616
本文介绍了在Qt中删除文件名的扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Qt从用户获取文件名:

I'm using Qt to get a file name from the user:

QString fileName = QFileDialog::getOpenFileName(this,tr("Select an image file"),"d:\\",tr("Image files(*.tiff *.tif )"));

它可以工作,但是我需要文件名不带扩展名,是有可能在Qt?
whenn我尝试:

It works, but I need the file name without its extension, is it possible in Qt?? whenn I try :

QString f = QFileInfo(fileName).fileName();

f 就像文件名.tif ,但我希望它成为文件名

f is like "filename.tif", but I want it to be "filename".

推荐答案

您可以使用。 分割 fileName 。像这样的分隔符:

You can split fileName with "." as separator like this:

QString croped_fileName=fileName.split(".",QString::SkipEmptyParts).at(0);

或使用QString的 section 函数。之前的第一部分。像这样:

or use section function of QString to take the first part before "." like this:

QString croped_fileName=fileName.section(".",0,0);

这篇关于在Qt中删除文件名的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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