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. Windows 10 QDir::separator

Windows 10 QDir::separator

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 5 Posters 337 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    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

    jsulmJ KroMignonK 2 Replies Last reply
    0
    • SPlattenS SPlatten

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • SPlattenS SPlatten

          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?

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @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
          5
          • O Offline
            O Offline
            ollarch
            wrote on last edited by
            #5

            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
            0

            • Login

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