Results 1 to 3 of 3

Thread: how can iterate foreach item in QListWidget

  1. #1
    Join Date
    May 2009
    Posts
    83

    Default how can iterate foreach item in QListWidget

    i just can find any example in the internet how to loop and get each item in the QListWidget. i need something like this : ( this is not working example ) :

    Qt Code:
    1. QListWidget* wl = ui.listWidget_selected;
    2. for (QWidget* w = wl.first(); w != 0; w = wl.next()) {
    3. {
    4. QString itemData = item->data(Qt::UserRole).toString();
    5. }
    To copy to clipboard, switch view to plain text mode 

    again this is not working

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: how can iterate foreach item in QListWidget

    QListWidget is not a list in a container way, it's a simple list view.

    Take a look at the QListWidget documentation and you can find there how to access the items within QListWidget.

  3. #3
    Join Date
    Apr 2011
    Posts
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can iterate foreach item in QListWidget

    Hi, this works:
    Qt Code:
    1. for (int i = 0; i < ui->listWidget->count(); i++) {
    2. QString itemData = ui->listWidget->item(i)->text();
    3. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to iterate through QListWidget items
    By zero-n in forum Newbie
    Replies: 6
    Last Post: 13th January 2012, 11:09
  2. QListWidget Item
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2008, 10:02
  3. QListWidget and selecting an item
    By invictus in forum Newbie
    Replies: 4
    Last Post: 19th June 2007, 12:59
  4. Iterate the QListWidget
    By vishal.chauhan in forum Newbie
    Replies: 1
    Last Post: 26th February 2007, 08:51
  5. Reg - add item in QListWidget
    By suresh in forum Newbie
    Replies: 1
    Last Post: 1st September 2006, 18:52

Tags for this Thread

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.