QDir 翻译

26 篇文章 0 订阅

前言:用这玩意,得先搞清楚路径和目录的区别,比如"mail"是个目录,但他的路径可能会是/var/spool/mail或者d:/shawhen/mail.当谈及路径时,它总是会被full-qualified

,这个类虽然叫QDir,但其实它能处理目录和路径

虽然文章名叫翻译,但我没逐字翻译,大致提炼了一下文意,然后用自己的语言(中文)表述

-------------------------------------------------------

QString QDir::dirName() const
Returns the name of the directory; this is not the same as the path, e.g. a directory with the name "mail", might have the path "/var/spool/mail". If the directory has no name (e.g. it is the root directory) an empty string is returned.


No check is made to ensure that a directory with this name actually exists; but see exists().


See also path(), filePath(), absolutePath(), and absoluteFilePath().

返回目录名称,返回一个dir的目录名称,这个函数并不会核实这个dir的目录名称的目录是否真实存在,相当于只是做一个字符分析而已.

------------------------------------------------------

QString QDir::canonicalPath() const

Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements.


On systems that do not have symbolic links this function will always return the same string that absolutePath() returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalPath() returns an empty string.


Example:


QString bin = "/local/bin";         // where /local/bin is a symlink to /usr/bin
QDir binDir(bin);
QString canonicalBin = binDir.canonicalPath();
// canonicalBin now equals "/usr/bin"


QString ls = "/local/bin/ls";       // where ls is the executable "ls"
QDir lsDir(ls);
QString canonicalLs = lsDir.canonicalPath();
// canonicalLS now equals "/usr/bin/ls".

See also path(), absolutePath(), exists(), cleanPath(), dirName(), and absoluteFilePath().

译:

函数意为返回一个dir的规范路径,为什么这么说,因为在许多文件系统中都有符号链接一说(不是windows快捷方式那种小儿科的玩意),通过这个函数,可以得到解析符号链接后的路径表示.同时也会去掉"."或者".."这些元素(.是当前路径,..是上级路径)

若在没有符号链接的系统中,这个函数的执行效果将与absolutePath()等同,如果对悬挂的符号链接调用此函数,将返回空值

------------------------------------------------------------------------

QString QDir::rootPath() [static]
Returns the absolute path of the root directory.


For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/".


See also root(), drives(), currentPath(), homePath(), and tempPath().

这是一个静态方法,返回操作系统的根目录的绝对路径,比如unix返回"/",windows通常返回"c:/",即c分区

----------------------------------------------------------------------

QFileInfoList QDir::drives() [static]
Returns a list of the root directories on this system.


On Windows this returns a list of QFileInfo objects containing "C:/", "D:/", etc. On other operating systems, it returns a list containing just one root directory (i.e. "/").


See also root() and rootPath().

这是一个静态方法,返回系统的根目录列表,在windows上返回所有驱动器列表,在其他操作系统上,返回一个只包含"/"的根目录

------------------------------------------------------------

QDir QDir::root() [static]
Returns the root directory.


The directory is constructed using the absolute path of the root directory, ensuring that its path() will be the same as its absolutePath().


See rootPath() for details.


See also drives(), current(), home(), and temp().

返回根目录的绝对路径的目录,注意,返回的是一个QDir,它的path()和absolutePath()等同

-------------------------------------------------------

QDir QDir::current() [static]
Returns the application's current directory.


The directory is constructed using the absolute path of the current directory, ensuring that its path() will be the same as its absolutePath().


See also currentPath(), setCurrent(), home(), root(), and temp().

这是一个静态方法,返回应用程序的当前目录(也称工作路径,即当你比如使用fopen("demo.txt")时,这些文件会生成在哪个路径),这个QDir是使用绝对路径构造的,可以保证返回的QDir的path()和absolutePath()等同

---------------------------------------------------------------

QString QDir::currentPath() [static]
Returns the absolute path of the application's current directory. The current directory is the last directory set with QDir::setCurrent() or, if that was never called, the directory at which this application was started at by the parent process.

这是一个静态方法,返回应用程序的当前路径(以绝对路径表示).当前目录是最近一次调用QDir::setCurrent()设置的值,如果彼函数未被调用过,当前目录即是被父进程开启时的目录

-----------------------------------------------------------------

QString QCoreApplication::applicationDirPath() [static]
Returns the directory that contains the application executable.


For example, if you have installed Qt in the C:\Qt directory, and you run the regexp example, this function will return "C:/Qt/examples/tools/regexp".


On Mac OS X this will point to the directory actually containing the executable, which may be inside of an application bundle (if the application is bundled).


Warning: On Linux, this function will try to get the path from the /proc file system. If that fails, it assumes that argv[0] contains the absolute file name of the executable. The function also assumes that the current directory has not been changed by the application.

这是一个静态方法,这会返回包含应用程序可执行文件的路径


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值