[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:



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")); // 

	return 0;

and your .pro file:

SOURCES += main.cpp

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


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