getting QString out of QListWidget
Hello,
I have a QListWidget list that I first fill with QStrings, then sort the list, and then I want to get the QStrings back out of the list. I don't know how to do that. Can you help? Below is my code with comments.
Code:
//"number" and "features" are int values
//"dataTable" is a table of integers
//declare QListWidget list
//fill QListWidget list with entries
for(int k=0; k<number+1; k++)
{
for(int i=0; i<features+1; i++)
{
entry.append(dataTable[i][k]);
entry.append(",");
}
sList->insertItem(k, entry);
}
//sort list entries in ascending order
sList->sortItems(Qt::AscendingOrder);
//get the list entries back in the QString format
//I DON'T KNOW HOW??
//QString entry2 = sList.itemAt(1); for example won't work
Thanks!
Re: getting QString out of QListWidget
Set this property to true first.
Code:
void setSortingEnabled ( bool enable )
Re: getting QString out of QListWidget
Try:
Code:
QString str
= sList.
item(1)->text
();
Re: getting QString out of QListWidget
Thanks!
However when I try to compile
Code:
QString entry2
= sList.
item(1)->text
();
I get:
error: 'item' has not been declared
But item is a function of QListWidgetItem, so why/where would I declare 'item'?
Is this happening because I don't build my QListWidget right?
Thanks!
Re: getting QString out of QListWidget
Is your existing code is working after setting the property ?
Re: getting QString out of QListWidget
you should use operator ->
Code:
QString entry2
= sList
->item
(1)->text
();
since you created sList in the heap.
Re: getting QString out of QListWidget
Yes, everything else is working properly. I just cannot get the QString back from the QList Widget.
Re: getting QString out of QListWidget
Hi Spirit,
Of course, you are correct. Everything is fixed now. Thanks!