void MainWindow::saveList( QStringList list ){ QSettings settings(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+ SETTINGSFORMAT, QSettings::IniFormat); int size; settings.beginWriteArray(LISTNAME, size = list.size()); for( int i = 0; i < size; i++ ) { settings.setArrayIndex( i ); settings.setValue( ITEMNAME, list.at( i ) ); } settings.endArray(); settings.sync()}
QStringList MainWindow::restoreList(){ QSettings settings(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+ SETTINGSFORMAT, QSettings::IniFormat); QStringList list; int size = settings.beginReadArray(LISTNAME); for( int i = 0; i < size; i++ ) { settings.setArrayIndex( i ); list << settings.value(ITEMNAME).toString(); } settings.endArray(); return list;}
void MainWindow::saveList( QStringList list ){ QSettings settings(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+ SETTINGSFORMAT, QSettings::IniFormat); int size; settings.remove( LISTNAME ) // added settings.beginWriteArray(LISTNAME, size = list.size()); for( int i = 0; i < size; i++ ) { settings.setArrayIndex( i ); settings.setValue( ITEMNAME, list.at( i ) ); } settings.endArray(); settings.sync()}