Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-126651

QFile::fileName() Get filename only

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 6.8
    • Core: I/O
    • None
    • All

    Description

      I have made file using abs path, so fW.fileName() returns abs path, but I want to get "W.txt" only... I suggest to add build-in mechanism of QFile to get filename only.

      My example

      QFile fW("/home/user/W.txt");
      fW.open(QIODevice::WriteOnly);
      fW.close();
      qDebug() << fW.fileName(); //print "/home/user/W.txt" instead of "W.txt"
      

      Of cause I can use this code to solve my problem

      qDebug() << QFileInfo(fW.fileName()).fileName(); //print "W.txt"

      But why I can't use my fW object only without QFileInfo() or QString?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            dungeonlords Andrei Cherniaev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes