Settings hierarchy

The simplest scenario assumes that settings are "flat", in that all keys are defined on the same level. However, this does not have to be the case—correlated settings can be put into named groups. To operate on a group, you can use the beginGroup() and endGroup() calls:

settings.beginGroup("server");
QString serverIP = settings.value("host").toString();
int port = settings.value("port").toInt();
settings.endGroup();

When using this syntax, you have to remember to end the group after you are done with it. An alternative way to do the same thing is to pass the group name directly to invocation of value(), using / to separate it from the value name:

QString serverIP = settings.value("server/host").toString(); int port = settings.value("server/port").toInt(); ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.