[Interest] QSettings: is a group present? Crash with qWarning.

Sensei senseiwa at gmail.com
Thu Aug 23 16:51:17 CEST 2012


Hi everyone.

Here's again a question, this time on QSettings with INI files. The 
question is simple: how do I know if a group exists in my INI file?

Well, I could ask for all groups with childGroups(), and use the 
contains("theGroupName") method.

Except that I don't know why this crashes when used inside a qWarning. 
This is the very simple INI file:



[first]
item=2

[last]
size=1




This is the super simple code I've written:



#include <QSettings>
#include <QStringList>

int main(int argc, char *argv[])
{	
	QSettings s("/Users/sensei/Desktop/proj.txp", QSettings::IniFormat);

	bool x = s.childGroups().contains("first");
	qWarning("Number of groups: %d", s.childGroups().size());
	qWarning("Contains [first]: %d", x); // OK
	qWarning("Contains [first]: %d", s.childGroups().contains("first")); // 
BOOM!

	return 0;
}


and your .pro file:

TEMPLATE = app
SOURCES += main.cpp




I don't know why this happens. Any hints? I might be missing something 
SO obvious...


Cheers!




PS. My environment is OSX 10.8, the qt installation is the one that I 
installed on the previous OSX version. Qt is 4.8.0 (the SDK Maintenance 
Tool says I have no updates available).



More information about the Interest mailing list