PDA

View Full Version : Problem reading a windows path from INI file value



rawfool
31st July 2013, 11:30
For a value in ini file, I have a windows path, which I need to read.

Ths is the content of my ini file


[Mozilla]
Dir1=C:\Firefox\sample\remediation
Dir2=C:\Firefox\properties\messages.ini
Dir3=C:\Firefox\sample\download.zip
Dir4=C:\Firefox\sample


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.


QSettings dwldFolder(qApp->applicationDirPath() + "/sample.ini", QSettings::IniFormat);
dwldFolder.beginGroup("Mozilla");
QString path = dwldFolder.value("Dir4").toString();
qDebug() << "Path" << path; // Here it is giving - C:Firefoxsample
dwldFolder.endGroup();


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?

Lesiok
31st July 2013, 12:28
Generally this is the correct behavior. How was the ini file created ?

rawfool
31st July 2013, 12:43
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.

yeye_olive
31st July 2013, 13:27
Use Windows' native API (http://msdn.microsoft.com/en-us/library/ms724353%28VS.85%29.aspx).

Santosh Reddy
31st July 2013, 17:34
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.