Qt Forum

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

    Unsolved Windows 10 QDir::separator

    General and Desktop
    5
    5
    133
    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.
    • SPlatten
      SPlatten last edited by

      I am building a path, I start off by using QFileDialog::getExistingDirectory to get a chosen path from the operator. On Windows 10 the path returned by this function contains / delimiting the folders.

      I then check if the returned path needs a delimiter appending with:

      QString strPath(QFileDialog::getExistingDirectory(this, "Choose location"));
      QChar chSeparator(QDir::separator());
      if ( strPath.endsWith(chSeparator) != true ) {
          strPath += chSeparator;
      }
      

      I can see in the debugger that chSeprator contains \ not the same delimiter as returned by getExistingDirectory, why is this and am I checking this correctly?

      Kind Regards,
      Sy

      jsulm KroMignon 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @SPlatten last edited by jsulm

        @SPlatten Qt uses / even on Windows. QDir::separator() returns native separator as explained in documentation (means: on Windows \). You can simply check for both / and \. Keep in mind that you have to escape \ if you want to use it in your paths.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

          People should really learn to sue the Search function... this same question was asked exactly three days ago: https://forum.qt.io/topic/128692/

          Qt has to stay free or it will die.

          1 Reply Last reply Reply Quote 1
          • KroMignon
            KroMignon @SPlatten last edited by

            @SPlatten Maybe this will not answer directly your question, but to avoid those kind of issues I always use QDir::cleanPath() to replace all \ with / and also removes all redondant separators.

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply Reply Quote 5
            • O
              ollarch last edited by

              Not question related, but this line:
              @SPlatten said in Windows 10 QDir::separator:

              if ( strPath.endsWith(chSeparator) != true )

              will be better in this way:

              if ( !strPath.endsWith(chSeparator) )
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post