Search code examples
c++qtqfile

get file address without file name from QFile


I have a Qfile with fileName="d://f1/f2/img.jpg". I just want the address of the file ("d://f1/f2). How can I get it without converting to a QfileInfo?


Solution

  • check this link:

    http://doc.qt.io/qt-4.8/qfileinfo.html#absolutePath

    file path:

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

    also file base name:

    QFileInfo fi("/tmp/archive.tar.gz");
    QString base = fi.baseName();  // base = "archive"