Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Get filename without extension

    General and Desktop
    5
    9
    23163
    Loading More Posts
    • 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
      szh1 last edited by

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

      1 Reply Last reply Reply Quote 0
      • F
        Felix last edited by

        i think QFileInfo might help you

        Vg

        Felix

        1 Reply Last reply Reply Quote 0
        • S
          szh1 last edited by

          Thanks. I'll try that.

          1 Reply Last reply Reply Quote 0
          • S
            szh1 last edited by

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

            1 Reply Last reply Reply Quote 0
            • S
              steno last edited by

              QFileInfo::baseName

              1 Reply Last reply Reply Quote 0
              • D
                DenisKormalev last edited by

                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 Reply Quote 0
                • S
                  szh1 last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • F
                    Felix last edited by

                    @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 Reply Quote 0
                    • F
                      Franzk last edited by

                      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 Reply Quote 0
                      • First post
                        Last post