Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QList Widget Getting text from Selected Index
vezprog last edited by
I am just starting to learn how to use QList Widgets. I am able to add items to my ListWidget, as well as select which one I want. What I want to do is when I click a button, I want to get the string that is selected (from the highlighted index within the list widget) and store it into a variable. Is this possible?
Thanks in advance.
Perhaps you want to use "currentItem()":http://doc.qt.nokia.com/4.7-snapshot/qlistwidget.html#currentItem on your QListWidget, and then "text()":http://doc.qt.nokia.com/4.7-snapshot/qlistwidgetitem.html#text on the returned QListWidgetItem.
amban last edited by
I have done the same thing this week. Here's what i did -
for (int list=0; list < listmodel->rowCount(); list++)
QStandardItem *newitem= listmodel->item(list);
if(newitem->checkState() == 2) //For all checked items
// store it into your variable using newitem->text()
There are several ways of doing it, this is one.
Hope this helps.