Results 1 to 7 of 7

Thread: Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

  1. #1
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4

    Default Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

    In Qt 4.6, I'm curious if anyone knows the reason why the string returned from QDir:ath() doesn't end with a "/".

    Also, I'm curious if anyone knows why QSettings does not tolerate backslashes in Windows configuration files. It appears that backslashes are read as escape characters. Why would anyone put escape characters in a configuration file?

    Thank you for your help.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

    Quote Originally Posted by johnkent222 View Post
    In Qt 4.6, I'm curious if anyone knows the reason why the string returned from QDir:ath() doesn't end with a "/".
    Why would it end with a slash?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

    Quote Originally Posted by johnkent222 View Post
    In Qt 4.6, I'm curious if anyone knows the reason why the string returned from QDir:ath() doesn't end with a "/".
    Because the Trolls decided to do so... And because normally a path does not end with a slash since it is superfluous.
    But since you noticed that, you won't get into trouble and you can just concat QDir::separator().
    Also, I'm curious if anyone knows why QSettings does not tolerate backslashes in Windows configuration files. It appears that backslashes are read as escape characters. Why would anyone put escape characters in a configuration file?
    Because the slash is "standard" and windows abused the escape character. But you can use "\\"...

  4. #4
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4

    Default Re: Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

    Thank you Lykurg. I figured it was a philosophical decision for them.

    I'm still confused as to why backslashes in configuration files would be treated as escape characters. It's not like anyone would put a "\t" in their config file instead of an actual tab (or would they?)

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

    If you mean that you can't do:
    Qt Code:
    1. QSettings settings(...);
    2. settings.setValue("some\thing", 7);
    To copy to clipboard, switch view to plain text mode 
    ...then QSettings has nothing to do with that. It's the compiler that treats the backslash as an escape character. If you did:
    Qt Code:
    1. QSettings settings(...);
    2. settings.setValue("some\\thing", 7);
    To copy to clipboard, switch view to plain text mode 
    ...it should work correctly.

  6. #6
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4

    Default Re: Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

    What happens is that if one of the parameters in an INI file (or any configuration file) is a windows path, a parameter like

    directory=C:\Directory\Path\

    when processed with QSettings, will return "C:irecotryath", treating "\D" and "\P" as escaped characters. Even in the documentation, it is stated that a Windows path in a INI settings file is not supported because they use backslashes, and backslashes are intended to escape characters.

    However, like you said, we use backslashes to escape characters in code, not in a plain text INI settings file. It seems odd that backslashes in an INI file would be treated as escape characters. The code in QSettings goes to great lengths to parse out backslashes and treat them as escape characters, so there must be a reason for it.

    Does anyone know what that reason is?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QDir::path() doesn't return a trailing slash, and backslashes in QSettings

    Wrap the value into quotes.

    directory="C:\Directory\Path\"

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2009, 03:29
  2. Replies: 2
    Last Post: 9th January 2009, 19:49
  3. QDir Path problem
    By ToddAtWSU in forum Qt Programming
    Replies: 3
    Last Post: 21st August 2008, 12:15
  4. QSettings::value() does not return value.
    By zEeLi in forum Qt Programming
    Replies: 3
    Last Post: 11th June 2007, 10:25
  5. Replies: 2
    Last Post: 8th August 2006, 15:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.