PDA

View Full Version : problem with "QListWidget" item



impeteperry
16th April 2007, 17:15
I have a QListWidget "lwlistData" and I want the text of the third item in the list . (n = 3);

I assume I should use
QListWidgetItem * QListWidget::item ( int row ) const

Returns the item that occupies the given row in the list if one has been set; otherwise returns 0. when I use
QString t = lwDataList->item(n - 1); I get
dlgmain.cpp:1067: error: invalid conversion from 'QListWidgetItem*' to 'char'
dlgmain.cpp:1067: error: initializing argument 1 of 'QString& QString::operator=(char)'

Please show what the command should be.

I have been using Qt3 and now Ot4 since it came out and I still have MAJOR trouble deciphering this stuff. I go to "more" and there is all kind of help for inserting items, but none that I can find on getting an item.

If for each command there was a simple example of it's use as there is on some of the commands, it would be wonderful for "stupid" people like me.
Thanks

high_flyer
16th April 2007, 17:21
The docs say it all - just make sure you read correctly ;)


QListWidgetItem * QListWidget::item ( int row ) const




1.
QString t = lwDataList->item(n - 1);


got it? ;)

try


QString t = lwDataList->item(n - 1)->text();

marcel
16th April 2007, 17:21
QString t = lwDataList->item(n - 1)->text();

JonathanForQT4
16th April 2007, 17:24
damnit, these two beat me to it :P

jpn
16th April 2007, 17:24
Use QListWidgetItem::text() to get the text of the item:


QString t = lwDataList->item(n - 1)->text();
// or more in a more safe way
QString t;
QListWidgetItem* item = lwDataList->item(n - 1);
if (item) t = item->text();


Edit: Damn, I'm slow today :p

marcel
16th April 2007, 17:38
Ok, give us our thanks now...
:)

impeteperry
16th April 2007, 18:00
Ok, give us our thanks now...
:)I certainly to