Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to save the text and the data from items from listwidget with QSettings?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 847 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    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..

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved