PDA

View Full Version : QListWidget not working???



janorcutt
17th February 2010, 12:50
hi, i'm wondering if anyone can help.. The following code compiles without error, and as far as i can see is ok. However the list widget does not display the items... the list widget is in list mode but doesnt show the items in icon mode either. Am i just being dumb, probably but any help would be great.


void myTunes::setupListWidget()
{
QIcon libraryIcon;
libraryIcon.addFile(QString::fromUtf8(":icons/icons/hi32-action-amarok_playlist.png"), QSize(),QIcon::Normal, QIcon::On);
QListWidgetItem libraryItem;
QListWidgetItem seperatorItem;;
libraryItem.setData(Qt::DecorationRole , libraryIcon);
libraryItem.setData(Qt::DisplayRole , " Music Library");
seperatorItem.setData(Qt::DisplayRole , " ----------");
ui->listWidget->insertItem(0 , &libraryItem);
ui->listWidget->insertItem(1 , &seperatorItem);
}

thnx janorcutt :confused:

Lykurg
17th February 2010, 12:59
Typical C++ failure: You have to create the items on the heap:
QListWidgetItem* libraryItem = new QListWidgetItem();

janorcutt
17th February 2010, 13:16
ok if i do that i get

error: request for member ‘setData’ in ‘libraryItem’, which is of non-class type ‘QListWidgetItem*’

:( i have the strange feeling all my hair is going to fall out on this project lol.
ok i'm going to keep trying, if any1 can suggest anything that would be top banana

thnx janorcutt

Lykurg
17th February 2010, 13:20
Well you have to use "->" instead of ".". Have a look at a basic c++ programming book about pointers and references. It could help you...

janorcutt
17th February 2010, 13:34
ok cheers for that. the problem I have is my 'book' is way out of date and doesnt cover qt at all. The really interesting thing is that i had this problem in qtcreator 1.2 before i upgraded it with synaptic to 1.3 which seems to detect weather you need pointers or references etc.
however i think a trip to a well stocked book shop is in order...

thanx again chap janorcutt :)