Results 1 to 7 of 7

Thread: QSettings doesn't return a text with backslashs inside quotes correctly

  1. #1
    Join Date
    Jul 2016
    Posts
    19
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QSettings doesn't return a text with backslashs inside quotes correctly

    Hello,

    Let say that I have the following ini file :

    [General]
    path="C:\Directory"

    But with :
    Qt Code:
    1. QSettings settings(_configFilePath, QSettings::IniFormat);
    2. qDebug()<<settings.value("path");
    To copy to clipboard, switch view to plain text mode 

    I get this result which is wrong : QVariant(QString, "C:irectory"). How can I get the correct path ?

    Thank you

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings doesn't return a text with backslashs inside quotes correctly

    Read QSettings doc. This problem is well described in.

  3. #3
    Join Date
    Jul 2016
    Posts
    19
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSettings doesn't return a text with backslashs inside quotes correctly

    Ok but I asked the question because according to the last answer of this thread : http://www.qtcentre.org/threads/2999...s-in-QSettings it is possible .

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings doesn't return a text with backslashs inside quotes correctly

    This thread is 6 years old. Something changed in Qt ? Generally backslash is an 'escape character'.
    Is this INI file used by another software ? Just use a slash ( / ) as path separator - it is working well on all Qt platforms.

  5. #5
    Join Date
    Jul 2016
    Posts
    19
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSettings doesn't return a text with backslashs inside quotes correctly

    In the ini file, users can change the path of an image used by my software. As I am working on windows, the file's path contains backslashes. So the only solution I have is to force users to write the path with normal slashes ?

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings doesn't return a text with backslashs inside quotes correctly

    First slash is legal path separator on Windows.
    Second I do not think manual tinkering with INI file by the user was a good idea.

  7. #7
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QSettings doesn't return a text with backslashs inside quotes correctly

    The backslash in a C++ string being an escape character has nothing to do with Qt of course. Just use a forward slash in your string literals as described in the docs, Qt does the translation to the native OS preference behind the scenes.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Replies: 7
    Last Post: 21st March 2014, 11:24
  2. Replies: 3
    Last Post: 17th April 2012, 17:05
  3. Replies: 1
    Last Post: 1st June 2011, 19:37
  4. Replies: 6
    Last Post: 22nd April 2010, 16:43
  5. QSettings::value() does not return value.
    By zEeLi in forum Qt Programming
    Replies: 3
    Last Post: 11th June 2007, 11:25

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.