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
QtWS25 Last Chance

Get filename without extension

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 25.5k 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 16 Aug 2010, 13:50 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 16 Aug 2010, 14:08 last edited by
      #2

      i think QFileInfo might help you

      Vg

      Felix

      1 Reply Last reply
      0
      • S Offline
        S Offline
        szh1
        wrote on 16 Aug 2010, 14:21 last edited by
        #3

        Thanks. I'll try that.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          szh1
          wrote on 16 Aug 2010, 15:22 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 16 Aug 2010, 15:39 last edited by
            #5

            QFileInfo::baseName

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on 16 Aug 2010, 19:28 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 16 Aug 2010, 19:30 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 16 Aug 2010, 20:06 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 17 Aug 2010, 05:56 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

                    3/9

                    16 Aug 2010, 14:21

                    topic:navigator.unread, 6
                    • Login

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