PDA

View Full Version : How to save the edited data in QListwidgetitem using a push button



Choti
11th January 2016, 11:31
Hello Everyone,

I am having a problem in saving the data obtained from Qlistwidgetitem. I am using a QListWidgetItem, where I am getting some data from the server on the window. Now I am able to edit the data whivch I got from the server. In the next step Ishould be able to save the data I have edited and send back to the server.

Please can anyone help me with this situation.

Thank you in advance :)

anda_skoa
11th January 2016, 12:02
It is hard to tell what part of the task you need help with?

Do you have a slot connected to the button?
Does that slot have access to the QListWidget?

Cheers,
_

Choti
11th January 2016, 12:28
11630


Thank you for your reply. Yes I have a slot connected to the button. As shown in the picture that was the data I recieved from the server. Now I am supposed to edit the "values" and save them and send back using the pushbutton SEND. I am able to edit the values but I am confused how to save the edited data.

anda_skoa
11th January 2016, 12:40
I assume this is about the second list and the values are all integers?

You can simply iterate over the list using QListWidget::count() and QListWidget::item() and for each item e.g. get the text with QListWidgetItem::text() and calling QString::toInt() to convert to integer.

Cheers,
_

Choti
11th January 2016, 13:04
The second list is a group of strings. Among all the values I am supposed to edit only two values which are non zero. Then I should save it and send back to the server.


void MainWindow::on_pushButton_clicked()
{
QListWidgetItem *list2 = ui->valueWidget->currentItem();

list2->setFlags(list2->flags()|Qt :: ItemIsEditable);

}


As shown in the code list2 is getting data from the server .

anda_skoa
11th January 2016, 14:00
So what actually do you need help with?

This code makes the current item editable.

Cheers,
_

Choti
11th January 2016, 14:29
Now I want to save the edited value .

anda_skoa
11th January 2016, 15:34
Well, get the value from the item (see comment #4) and save it.

Cheers,
_