QSettings not returning keys of the predefined .ini file
-
Hi,
I'm having predefined.ini
file
It's contents are:[Personal]//I want these to be groups in the QSettings object, Later I may display the contents of each group. Name=Abc Age=10 [Education] Highest=Phd [Interests] hobby=volleyball [these_may_grow]// I need to scan all the [ ] these_may_grow=these_may_grow
I have global QSettings object, I initialized in the constructor, now I want to read the predefined
.ini
file and create a group([contents of this]).code to retrieve values in predefined
.ini
I have developed is :iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here //If I do the following codes qDebug()<<iniSettings->group();//returns " " qDebug()<<iniSettings->allKeys();//returns ()
Where am I failing?
-
Hi,
I'm having predefined.ini
file
It's contents are:[Personal]//I want these to be groups in the QSettings object, Later I may display the contents of each group. Name=Abc Age=10 [Education] Highest=Phd [Interests] hobby=volleyball [these_may_grow]// I need to scan all the [ ] these_may_grow=these_may_grow
I have global QSettings object, I initialized in the constructor, now I want to read the predefined
.ini
file and create a group([contents of this]).code to retrieve values in predefined
.ini
I have developed is :iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here //If I do the following codes qDebug()<<iniSettings->group();//returns " " qDebug()<<iniSettings->allKeys();//returns ()
Where am I failing?
Please check that the filename can be sucessfully resolved.
Please note that the constructor does not take a filename, but instead an organisation and an application name.
Regards
-
Please check that the filename can be sucessfully resolved.
Please note that the constructor does not take a filename, but instead an organisation and an application name.
Regards
-
Hi,
I'm having predefined.ini
file
It's contents are:[Personal]//I want these to be groups in the QSettings object, Later I may display the contents of each group. Name=Abc Age=10 [Education] Highest=Phd [Interests] hobby=volleyball [these_may_grow]// I need to scan all the [ ] these_may_grow=these_may_grow
I have global QSettings object, I initialized in the constructor, now I want to read the predefined
.ini
file and create a group([contents of this]).code to retrieve values in predefined
.ini
I have developed is :iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here //If I do the following codes qDebug()<<iniSettings->group();//returns " " qDebug()<<iniSettings->allKeys();//returns ()
Where am I failing?
@thippu said in QSettings not returning keys of the predefined .ini file:
iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here
//If I do the following codes
qDebug()<<iniSettings->group();//returns " "
qDebug()<<iniSettings->allKeys();//returns ()you need to call QSettings::beginGroup() before reading/writing
also you can check if the return value ofQFile::exists(filename)
if the application really can find your ini-file. -
@thippu said in QSettings not returning keys of the predefined .ini file:
iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here
//If I do the following codes
qDebug()<<iniSettings->group();//returns " "
qDebug()<<iniSettings->allKeys();//returns ()you need to call QSettings::beginGroup() before reading/writing
also you can check if the return value ofQFile::exists(filename)
if the application really can find your ini-file.@raven-worx Yes, I did
qDebug()<<QFile(filename).exists();
it returned metrue
. -
@thippu said in QSettings not returning keys of the predefined .ini file:
iniSettings->setPath(QSettings::IniFormat,QSettings::UserScope,filename);// filename is a global variable here
//If I do the following codes
qDebug()<<iniSettings->group();//returns " "
qDebug()<<iniSettings->allKeys();//returns ()you need to call QSettings::beginGroup() before reading/writing
also you can check if the return value ofQFile::exists(filename)
if the application really can find your ini-file.@raven-worx for
beginGroup()
,iniSetting->beginGroup("[")
;// I doubt it will work as per.ini
filestructure? -
@raven-worx for
beginGroup()
,iniSetting->beginGroup("[")
;// I doubt it will work as per.ini
filestructure?@thippu
with respect to your ini file from your first post you should call:iniSettings->beginGroup("Personal"); iniSettings->value("Age"); iniSettings->endGroup();
or alternatively (if you don't have a group set!):
iniSettings->value("Personal/Age");
-
And in addition to what @raven-worx says, you need to use this constructor if you want to specify the filename.
Otherwise QSettings calculates the filename itself.
-
@thippu
with respect to your ini file from your first post you should call:iniSettings->beginGroup("Personal"); iniSettings->value("Age"); iniSettings->endGroup();
or alternatively (if you don't have a group set!):
iniSettings->value("Personal/Age");
@raven-worx Yes bro, in that
.ini
example,[groupname]
// may grow and I want to scan them dynamically, how to do it? -
@raven-worx for
beginGroup()
,iniSetting->beginGroup("[")
;// I doubt it will work as per.ini
filestructure? -
@raven-worx okay, I have included in the constructor itself.
code:iniSettings=new QSettings(filename,QSettings::IniFormat,this);
-
@raven-worx okay, I have included in the constructor itself.
code:iniSettings=new QSettings(filename,QSettings::IniFormat,this);
@thippu
and? it's working now? -
@thippu
and? it's working now?@raven-worx bro, in
.ini
) can grow, I want to scan them dynamically, so what to include inbeginGroup()
?, please help me. -
@thippu
and? it's working now?@raven-worx Yes, bro working. failure was the happing because of the constructor, after setting it properly it working now, I did
I can't thank enough to guys @raven-worx , @aha_1980qDebug()<<iniSettings->childGroups();//returns all the heading names````
-
@raven-worx bro, in
.ini
) can grow, I want to scan them dynamically, so what to include inbeginGroup()
?, please help me.@thippu
with the usage of the right Constructor your ini-file should be read correctly now.
So now you can use QSettings::childGroups() to traverse all groups and read the values as i described above or with the use of QSettings::beginGroup() and QSettings::childKeys()foreach( QString group, iniSettings->childGroups() ) { // process group iniSettings->beginGroup(group); foreach( QString key, iniSettings->childKeys() ) { QVariant val = iniSettings->value(key); // process val } iniSettings->endGroup(); }
-
@thippu
with the usage of the right Constructor your ini-file should be read correctly now.
So now you can use QSettings::childGroups() to traverse all groups and read the values as i described above or with the use of QSettings::beginGroup() and QSettings::childKeys()foreach( QString group, iniSettings->childGroups() ) { // process group iniSettings->beginGroup(group); foreach( QString key, iniSettings->childKeys() ) { QVariant val = iniSettings->value(key); // process val } iniSettings->endGroup(); }
@raven-worx
uh hu, using deprecated syntax/macros, shame on you ;-) -
@thippu
with the usage of the right Constructor your ini-file should be read correctly now.
So now you can use QSettings::childGroups() to traverse all groups and read the values as i described above or with the use of QSettings::beginGroup() and QSettings::childKeys()foreach( QString group, iniSettings->childGroups() ) { // process group iniSettings->beginGroup(group); foreach( QString key, iniSettings->childKeys() ) { QVariant val = iniSettings->value(key); // process val } iniSettings->endGroup(); }
@raven-worx Sure bro, I will use this code to create group and contents of the group.
-
@raven-worx
uh hu, using deprecated syntax/macros, shame on you ;-)@J.Hilk said in QSettings not returning keys of the predefined .ini file:
uh hu, using deprecated syntax/macros, shame on you ;-)
yes, i am still too lazy for such a convenient function to deprecate it also in my head ;)