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. Get filename without extension

Get filename without extension

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 25.6k Views
  • 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.
  • S Offline
    S Offline
    szh1
    wrote on last edited by
    #1

    How can I get a filename without the extension from a QString?
    Thanks.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Felix
      wrote on last edited by
      #2

      i think QFileInfo might help you

      Vg

      Felix

      1 Reply Last reply
      0
      • S Offline
        S Offline
        szh1
        wrote on last edited by
        #3

        Thanks. I'll try that.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          szh1
          wrote on last edited by
          #4

          What function in QFileInfo will give me the filename without the extension?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            steno
            wrote on last edited by
            #5

            QFileInfo::baseName

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              I think better QString::remove() should be used. Based either on previously found index of extension begin or on regexp it will be more flexible for further changes.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                szh1
                wrote on last edited by
                #7

                I tried QFileInfo::baseName and it worked perfectly. Thank you for the help.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  Felix
                  wrote on last edited by
                  #8

                  @Denis that cant really be used sometimes i think. If you dont now the extension of the file, its quite ugly to find the extension in a string because of many special cases like differnt length or ".tar.gz" with several "." . So just taking this method save a lot of pain in my opinion

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Franzk
                    wrote on last edited by
                    #9

                    QFileInfo does probably exactly what Denis said. However, since someone else did the effort for you, there is absolutely no reason not to use QFileInfo.

                    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    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