Search code examples
qtqt4

Get filename from QFile?


eg:

QFile f("/home/umanga/Desktop/image.jpg");

How I get only the filename - "image.jpg"?


Solution

  • Use a QFileInfo to strip out the path (if any):

    QFileInfo fileInfo(f.fileName());
    QString filename(fileInfo.fileName());