当前位置: 代码迷 >> QT开发 >> Qt 路径有关问题
  详细解决方案

Qt 路径有关问题

热度:63   发布时间:2016-04-25 03:57:56.0
Qt 路径问题
用QFile开打文件后怎么显示文件的路径, 并且显示出来。或者用其他的函数也可以

------解决方案--------------------
QString QFile::fileName()
------解决方案--------------------
QFileInfo fi(file);
QString str = fi.absolutePath();
str里是文件的绝对路径。

引用:
用QFile开打文件后怎么显示文件的路径, 并且显示出来。或者用其他的函数也可以

------解决方案--------------------
QFileInfo有个方法
QString QFileInfo::absoluteFilePath () const

Returns an absolute path including the file name.

The absolute path name consists of the full path and the file name. On Unix this will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'. QFileInfo will uppercase drive letters. Note that QDir does not do this. The code snippet below shows this.

     QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"

你可以用QFile去构造QFileInfo
用到构造函数
QFileInfo ( const QFile & file )
  相关解决方案