PDA

View Full Version : QListWidget item value extracted



hojoff79
24th January 2011, 09:00
I cannot figure out how to extract the value of a selected item from a QListWidget.

For example, say I have a list with three items "Hello", "Goodbye", "Goodmorning".

The user interface has a push button, the QListWidget and a label.
I have a slot connected to the clicked() button in which I want the selected item from the list widget, that value is put into the value of the label using ui->label->setText(value); What I don't understand is how to extract the value from the selected item in the QListWidget. Thank you in advance.

tbscope
24th January 2011, 09:31
Assuming that you can only select one item in the list, you can use:
http://doc.qt.nokia.com/4.7/qlistwidget.html#currentItem

But before using it, check if the pointer is valid. I think the first time the program starts, there's no item selected.