Get filename without extension
-
wrote on 16 Aug 2010, 13:50 last edited by
How can I get a filename without the extension from a QString?
Thanks. -
wrote on 16 Aug 2010, 14:08 last edited by
i think QFileInfo might help you
Vg
Felix
-
wrote on 16 Aug 2010, 14:21 last edited by
Thanks. I'll try that.
-
wrote on 16 Aug 2010, 15:22 last edited by
What function in QFileInfo will give me the filename without the extension?
-
wrote on 16 Aug 2010, 15:39 last edited by
QFileInfo::baseName
-
wrote on 16 Aug 2010, 19:28 last edited by
I think better QString::remove() should be used. Based either on previously found index of extension begin or on regexp it will be more flexible for further changes.
-
wrote on 16 Aug 2010, 19:30 last edited by
I tried QFileInfo::baseName and it worked perfectly. Thank you for the help.
-
wrote on 16 Aug 2010, 20:06 last edited by
@Denis that cant really be used sometimes i think. If you dont now the extension of the file, its quite ugly to find the extension in a string because of many special cases like differnt length or ".tar.gz" with several "." . So just taking this method save a lot of pain in my opinion
-
wrote on 17 Aug 2010, 05:56 last edited by
QFileInfo does probably exactly what Denis said. However, since someone else did the effort for you, there is absolutely no reason not to use QFileInfo.
2/9