Results 1 to 5 of 5

Thread: QListWidget not working???

  1. #1
    Join Date
    Feb 2010
    Location
    Wokingham, United Kingdom
    Posts
    36
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QListWidget not working???

    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.

    Qt Code:
    1. void myTunes::setupListWidget()
    2. {
    3. QIcon libraryIcon;
    4. libraryIcon.addFile(QString::fromUtf8(":icons/icons/hi32-action-amarok_playlist.png"), QSize(),QIcon::Normal, QIcon::On);
    5. QListWidgetItem libraryItem;
    6. QListWidgetItem seperatorItem;;
    7. libraryItem.setData(Qt::DecorationRole , libraryIcon);
    8. libraryItem.setData(Qt::DisplayRole , " Music Library");
    9. seperatorItem.setData(Qt::DisplayRole , " ----------");
    10. ui->listWidget->insertItem(0 , &libraryItem);
    11. ui->listWidget->insertItem(1 , &seperatorItem);
    12. }
    To copy to clipboard, switch view to plain text mode 

    thnx janorcutt

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget not working???

    Typical C++ failure: You have to create the items on the heap:
    Qt Code:
    1. QListWidgetItem* libraryItem = new QListWidgetItem();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    janorcutt (17th February 2010)

  4. #3
    Join Date
    Feb 2010
    Location
    Wokingham, United Kingdom
    Posts
    36
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget not working???

    ok if i do that i get
    Qt Code:
    1. error: request for member ‘setData’ in ‘libraryItem’, which is of non-class type ‘QListWidgetItem*’
    To copy to clipboard, switch view to plain text mode 

    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

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget not working???

    Well you have to use "->" instead of ".". Have a look at a basic c++ programming book about pointers and references. It could help you...

  6. The following user says thank you to Lykurg for this useful post:

    janorcutt (17th February 2010)

  7. #5
    Join Date
    Feb 2010
    Location
    Wokingham, United Kingdom
    Posts
    36
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget not working???

    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

Similar Threads

  1. My first app not working
    By Noks in forum Newbie
    Replies: 6
    Last Post: 2nd February 2010, 16:34
  2. Why Ctrl+A not working in QListWidget?
    By rajesh in forum Qt Programming
    Replies: 6
    Last Post: 10th December 2009, 14:40
  3. QListWidget help please
    By munna in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2006, 12:16
  4. Another QListWidget bug?
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2006, 13:40
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.