Qt学习Qt随笔

Qt随笔 - QFileInfo的各种超坑函数

2017-02-11  本文已影响262人  静_谷
Qt.io的新主页背景

QFileInfo是一站式超大型编程函数主业GUI超市Qt提供的一个可以访问文件信息属性的class,但是笔者最近在使用QFileInfo时对面前屡屡闪现的十分相同的函数疑惑不解,终于今天查了一下Doc,真相大白……


先看看路径类的吧!

QFileInfo info(“D:\UserData\hello.exe”);
info.path();
//Return the path like “D:\UserData”

所以这个是返回文件的路径但不包含文件名

QFileInfo info(“D:\UserData\hello.exe”);
info.filePath();
//Return the path like “D:\UserData\hello.exe”

所以这个是返回文件的路径也包含文件名,再次仰天长啸~


QFileInfo info(“D:\UserData\hello.exe”);
info.fileName();
//Return the path like “hello.exe”

所以是返回文件名啦

QFileInfo info(“D:\UserData\hello.exe”);
info.baseName();
//Return the path like “hello”
QFileInfo info(“D:\UserData\hello.tar.gz”);
info.fileName();
//Return the path like “hello.tar”

笔者也不知如何描述,看栗子,自悟吧……

QFileInfo info(“D:\UserData\hello.tar.gz”);
info.fileName();
//Return the path like “gz”

返回后缀名

QFileInfo info(“D:\UserData\hello.tar.gz”);
info.fileName();
//Return the path like “tar.gz”

唉,无语中……

很强大,很丰富,很多坑……

上一篇 下一篇

猜你喜欢

热点阅读