Results 1 to 5 of 5

Thread: Problem reading a windows path from INI file value

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Problem reading a windows path from INI file value

    For a value in ini file, I have a windows path, which I need to read.

    Ths is the content of my ini file
    Qt Code:
    1. [Mozilla]
    2. Dir1=C:\Firefox\sample\remediation
    3. Dir2=C:\Firefox\properties\messages.ini
    4. Dir3=C:\Firefox\sample\download.zip
    5. Dir4=C:\Firefox\sample
    To copy to clipboard, switch view to plain text mode 

    Here from Dir4 I need to take the value. But it's taking as escape sequences & giving me output as C:Firefoxsample.

    This is how I'm reading from the file.
    Qt Code:
    1. QSettings dwldFolder(qApp->applicationDirPath() + "/sample.ini", QSettings::IniFormat);
    2. dwldFolder.beginGroup("Mozilla");
    3. QString path = dwldFolder.value("Dir4").toString();
    4. qDebug() << "Path" << path; // Here it is giving - C:Firefoxsample
    5. dwldFolder.endGroup();
    To copy to clipboard, switch view to plain text mode 

    How do I convert it to C:\\Firefox\\sample or C:/Firefox/sample?

    And in documentation it's mentioned as QSettings always treats backslash as a special character and provides no API for reading or writing such entries. Any work around?
    Last edited by rawfool; 31st July 2013 at 12:00.

  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: Problem reading a windows path from INI file value

    Generally this is the correct behavior. How was the ini file created ?

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem reading a windows path from INI file value

    INI file is not created by my application, it's created by other non-qt application. I need to read a value (path) from the existing INI.

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem reading a windows path from INI file value

    Use Windows' native API.

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Problem reading a windows path from INI file value

    It would be better to read the ini file using the same API which created it in the first place, otherwise you may end up with other API incompatibilities.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Add platform dependent path into pro file problem
    By alizadeh91 in forum Qt Programming
    Replies: 5
    Last Post: 7th October 2012, 01:06
  2. Replies: 1
    Last Post: 22nd May 2012, 01:28
  3. QRegExp validate windows file path
    By niol1000 in forum Newbie
    Replies: 2
    Last Post: 30th January 2010, 15:06
  4. Problem to find file path
    By phillip_Qt in forum Qt Programming
    Replies: 14
    Last Post: 28th April 2008, 10:06
  5. Replies: 0
    Last Post: 14th December 2007, 01:33

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.