• Qt QFileInfo 各种函数


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


    先看看路径类的吧!

    1 QFileInfo::path()
    2 QString QFileInfo::path() const

    看起来十分的单纯,而且与预料中的一样,殊不知,这个函数的确是返回file's path,但是后面跟了一句“This doesn't include the file name.”,啊~~,仰天长啸……
    栗子:

    1 QFileInfo info(“D:UserDatahello.exe”);
    2 info.path();
    3 //Return the path like “D:UserData”

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


    1 QFileInfo::filePath()
    2 QString QFileInfo::filePath() const

    这又是什么鬼?!
    栗子:

    1 QFileInfo info(“D:UserDatahello.exe”);
    2 info.filePath();
    3 //Return the path like “D:UserDatahello.exe”

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


    1 QFileInfo::fileName
    2 QString QFileInfo::fileName() const

    终于把路径类的函数看完了,现在开始文件名类啰
    栗子:

    1 QFileInfo info(“D:UserDatahello.exe”);
    2 info.fileName();
    3 //Return the path like “hello.exe”

    所以是返回文件名啦


    1 QFileInfo::baseName
    2 QString QFileInfo::baseName() const

    好吧,我承认不知道基本(base)和普通的差别
    栗子:

    1 QFileInfo info(“D:UserDatahello.exe”);
    2 info.baseName();
    3 //Return the path like “hello”

    1 QFileInfo::completeBaseName
    2 QString QFileInfo::completeBaseName() const

    是不是已经头晕眼花,四肢无力,两眼昏昏,几欲先走?
    别忙,还有!
    栗子:

    1 QFileInfo info(“D:UserDatahello.tar.gz”);
    2 info.fileName();
    3 //Return the path like “hello.tar”

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


    1 QFileInfo::suffix
    2 QString QFileInfo::suffix() const

    suffix译为“后缀名”,所以——

    1 QFileInfo info(“D:UserDatahello.tar.gz”);
    2 info.fileName();
    3 //Return the path like “gz”

    返回后缀名


    1 QFileInfo::completeSuffix
    2 QString QFileInfo::completeSuffix() const

    QFileInfo::completeBaseName差不多吧
    大侠请看!

    1 QFileInfo info(“D:UserDatahello.tar.gz”);
    2 info.fileName();
    3 //Return the path like “tar.gz”

    唉,无语中……

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

     
  • 相关阅读:
    jQuery radio的取值与赋值
    MVC中一般为什么用IQueryable而不是用IList?用IQueryable比IList好在哪?
    Git 的 .gitignore 配置
    XPath学习:轴(3)——descendant
    python遍历数组的两种方法
    selenium webdriver的各种driver
    Scrapy and Selenium
    scrapy和selenium结合抓取动态网页
    Python处理JSON
    Crontab定时任务配置
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/13723694.html
Copyright © 2020-2023  润新知