How to save the text and the data from items from listwidget with QSettings?



  • So i have a listwidget with 5 items with text:
    @item1
    item2
    item3
    item4
    item5@

    they also have some data saved at Data(32)/33,34.

    what i want is when i close the program the program should save everything not just the text of the items..

    I use this
    @void MainWindow::closeEvent( QCloseEvent * )
    {
    QSettings settings( "App", "Settings" );
    if(ui->listWidget->count()!=0)
    {
    int check_point=ui->listWidget->count();

        settings.beginWriteArray("listwidgetitem");
        for (int i = check_point-1; i >= 0; --i) {
            settings.setArrayIndex(i);
            settings.setValue("item", ui->listWidget->item(i)->text() );
        }
        settings.endArray();
    }
    

    }@

    to save the texts of the items..but how can i save the datas as well? something like this:

    @void MainWindow::closeEvent( QCloseEvent * )
    {
    QSettings settings( "App", "Settings" );
    if(ui->listWidget->count()!=0)
    {
    int check_point=ui->listWidget->count();

        settings.beginWriteArray("listwidgetitem");
        for (int i = check_point-1; i >= 0; --i) {
            settings.setArrayIndex(i);
            settings.setValue("item", ui->listWidget->item(i)->text() , ui->listwidget->item(i)->Data(32), ui->listwidget->item(i)->Data(34), ui->listwidget->item(i)->Data(34));
        }
        settings.endArray();
    }
    

    }@

    It's a complicated question, tell me if you don't understand..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.