PDA

View Full Version : QListWidget difficulty getting item text and iterating



furiousrox
31st August 2010, 05:20
Hello,

Im newbie, and I wish somebody helps me getting the text value of a Row in a QListWidget named list_result, sum it with the other values and then display on an Edit.

I need to iterate it so i can sum all the numbers in the list, but i dont know how to get the TEXT out of it... Also, I think I need to turn the text into a float type to calculate, but i can't get it working, tried many combinations of codes.... Somebody help me please :(





float sum = 0;
float sum2 = 0;


//do the loop thing
for (int = 0; i<list_result->count(); i++) {

//get the text from each row of the QListWidget, and transform to Float (?)
sum2 = ???

//sum the numbers
sum = sum + sum2;

}

//show the result in an Edit by transforming into a String
ed_result->setText(QString::number(sum));





Edit: Qt version 4.6.2

aamer4yu
31st August 2010, 05:26
Have a look at
QListWidget::item
and
QListWidgetItem::text

furiousrox
31st August 2010, 05:27
have read that many times, but the usage of it is not clear to me... :(

furiousrox
31st August 2010, 05:33
if i use like


sum2 = list_result->item(i).toFloat();

i get this error:

error: request for member 'to Float' in .......item(i) which is of non-class type 'QListWidgetItem'

furiousrox
31st August 2010, 05:42
ooohhh yeahhh i got it

its:


sum2 = list_result->item(i)->text().toFloat();

god!

Thanks for the help. :)