How can we edit the QListWidgets items and send the values back?
Hello everyone,
I am new to Qt programming. I was working on a application where I am supposed to read the configuration paramenters from a server and the I am supposed to edit those values and send it back.
In the first step I did coding on eclipse, such that when I run my program I get the configuration parameters from the server. the communication takes place through TCP connection.
Now in the second step, I supposed to develop a GUI application using Qt, where I can see all the values on the window when I run the program. So far I am able to get the values on window. I did this program using QListWidget addItem, now in the next step I have to make the values editable. these values are coming from the server, so have to edit them and send back to the server.
Can anyone help with this issue? I was trying to add the editItem and I have even tried using the setFlags, but nothing is working.
thank you in advance.
Re: How can we edit the QListWidgets items and send the values back?
i thought you'd better use qlistwidgetitem's subclass as item in your widget, you should override data, setFlags, setData methods for showing data, editable data and store data. after that, you must use setItemWidget method to add your item in widget for you operate data.
-- sory about bad english.
Re: How can we edit the QListWidgets items and send the values back?
Thank you for your reply... I tried with qlistwidgetitem but then I was unable to get the data..
if (retVal == SOAP_OK) {
// loop over all configurationKeys
QListWidget *list1 = w.findChild<QListWidget *>("keyWidget");
//QListWidget *list2 = w.findChild<QListWidget *>("valueWidget");
QListWidgetItem *list2 = new QListWidgetItem("valueWidget");
list2->setFlags(list2->flags()|Qt :: ItemIsEditable);
std::vector<cp__KeyValue *>::iterator it;
for (it = getConfResponse->configurationKey.begin(); it != getConfResponse->configurationKey.end(); ++it) {
//std::cout << "key is" << (*it)->key;
list1->addItem(QString::fromStdString((*it)->key));
//list2->addItem(QString::fromStdString(*(*it)->value).toStdString().c_str());
//list2->addItem(QString::fromStdString(*(*it)->value));
// BOOST_LOG(lg) << "Value :" << (*((*it)->value) != NULL : *((*it)->value) "not defined");
if((*it)->value !=NULL)
{
BOOST_LOG(lg) << " Key :: " << (*it)->key << " Value :: " << (*(*it)->value);
cout << " Key :: " << (*it)->key << " Value :: " << (*(*it)->value);
//list2->addItem(QString::fromStdString(*(*it)->value));
//list2->setText(QString::fromStdString(*(*it)->value));
list2->setData(Qt::DisplayRole, QString::fromStdString(*(*it)->value) );
}
else
{
BOOST_LOG(lg) << " Key :: " << (*it)->key << " Value :: " << (*it)->value;
cout << " Key :: " << (*it)->key << " Value :: " << (*it)->value;
//list2->addItem("0");
}
As we see in the code, when I try to use qlistwidgetitem I am getting empty message on the output
Re: How can we edit the QListWidgets items and send the values back?
it means that you have read data from severs in Qt application and you saw them, however you can't send your data to server?