Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Seperate Path and File from a QString or a QFile
Forum Updated to NodeBB v4.3 + New Features

Seperate Path and File from a QString or a QFile

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 39.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    evergreen
    wrote on last edited by
    #1

    Hello,

    As the title says, I want to get the file name out of a FilePath to change the name of the file before saving it.
    As a matter of fact, my application has to be runable on all OS so it' s not really possible to play on splitting the QString.

    I was surprised not to find a way to do it directly in the doc.

    Does anyone know how to do it?

    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maciej
      wrote on last edited by
      #2

      You can do it with splitting the QString. Just get separator with QDir::separator().

      Earth is a beta site.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Thanatos.jsse
        wrote on last edited by
        #3

        you can use:
        @// fileName that contains the full file path name and is a QString type
        QFile file(fileName);
        if (file.exist()) {
        // Message
        } else {
        // your method
        QString name = file.fileName(); // Return only a file name
        } @

        Best regards

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          You can instantiate a "QFileInfo":http://doc.qt.nokia.com/latest/qfileinfo.html with your file passed in constructor. Then you can use a lot of getting functions from QFileInfo.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Thanatos.jsse
            wrote on last edited by
            #5

            [quote author="cincirin" date="1305814593"]You can instantiate a "QFileInfo":http://doc.qt.nokia.com/latest/qfileinfo.html with your file passed in constructor. Then you can use a lot of getting functions from QFileInfo.[/quote]

            That's right... other way to acces to file information.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              evergreen
              wrote on last edited by
              #6

              Thanks for the answers.
              they all have helped a lot.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved