Hello. I have a text editor. When closing the program, I save the name and path to the file in the registry, so that when I open it I open it. Opening:

QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); settings.setValue("hyperText/fileName", fileName); settings.setValue("hyperText/fileUrl", fileUrl); settings.sync(); 

Reading:

 QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); return settings.value("hyperText/fileUrl" + "hyperText/fileName"); 

But how to save and open the path and file name if there are several of them (without knowing their number first)?

  • one
    Save a QStringList with a list of files, it is supported in QSettings out of the box without the need of crutches - Bearded Beaver

1 answer 1

This can be approached differently, for example, in QSettings there is a pair beginWriteArray / endArray . In the same place, in documentation, there is also an example of use. This is the preferred method.

Alternatively, you can use the fact that a QList can be serialized into a QDataStream using operator<< and write one value to the registry, first turning the list into one line.