QTSettings with ini file format ignores first section unless preceded by comment
Hi all,
I am getting bizarre behaviour from QSettings
I want to use it with an ini file.
so I do something like this
Now if I have a first "section"( beginning with [Env]) then all settings in that section are ignored: reading with m_settings->value(...) returns the "fallback" value.
The following sections are properly read however
Now if I precede by first section with a comment starting with # then mysteriously all settings in that ini file are read properly.
Is this a bug or a feature or is a Byte Order Mark doing its dirty work here?
Re: QTSettings with ini file format ignores first section unless preceded by comment
Works for me
Code:
#include <QDebug>
#include <QSettings>
#include <QStringList>
#include <QTemporaryFile>
#include <QTextStream>
int main()
{
if ( !tmpFile.open() ) {
return 1;
}
const QString fileName
= tmpFile.
fileName();
stream <<
QLatin1String( "[Env]" ) << endl <<
"Driver=QSQLITE" << endl;
stream << "Name=some name" << endl;
tmpFile.close();
qDebug() << "childGroups=" << settings.childGroups();
qDebug() << "Driver=" << settings.value("Env/Driver");
qDebug() << "Name=" << settings.value("Env/Name");
return 0;
}
I get
Code:
childGroups= ("Env")
Cheers,
_