Beispiel für das Speichern einer Datei:
void SettingsData::saveSettings() { QString folder = "/path/to/folder/"; QString fileName = folder + "settings.xml";
//prüfen ob Verzeichnis exitisert, ggf. anlegen
QDir dir(folder);
if (!dir.exists()) {
dir.mkpath(".");
}
//XML-Datei:
QFile file(fileName);
file.open(QFile::WriteOnly | QFile::Text);
QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("settings");
xmlWriter.writeTextElement("minutes", 25);
xmlWriter.writeTextElement("pause", 10);
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
file.close();
}