Results 1 to 8 of 8

Thread: QListWidget->clear()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget->clear()

    Try using this:

    The QListWidget destroys your array of QListWidgetItems during the clear (so the first time it's not a problem the second time is). this code generates new items when they are needed

    Qt Code:
    1. qDebug("inside updatelist");
    2. quint8 qIndex;
    3.  
    4. ui->listWidget->setWrapping(false);
    5. // ui->listWidget->clear();
    6.  
    7. qDebug()<<"total items = "<<tot_items;
    8. for (qIndex = 0; qIndex < tot_items; ++qIndex)
    9. {
    10. qDebug("inside for loop");
    11. QString item_val = QString(ItemsInList[qIndex].name).append("\n").append(QString("$").append(ItemsInList[qIndex].price));
    12. qDebug()<<"list widget string to be populated = "<<item_val;
    13. item.setText(item_val);
    14. QString icon = QString("/home/charvi123/QtSDK/Projects/scanIt/numbers/") + QString("%1").arg((qIndex + 1), 0, 10) + QString(".png");
    15. item.setIcon(QIcon(icon));
    16. ui->listWidget->addItem(item);
    17. }
    18. ui->listWidget->setFocus();
    To copy to clipboard, switch view to plain text mode 

    Question why do you want to save the data twice? once in the item array and once in the listwidget
    For this i would use the QStandardItemModel in combination with the QListView
    Last edited by StrikeByte; 13th August 2012 at 10:34.

Similar Threads

  1. clear all QLineEdit
    By jaca in forum Qt Programming
    Replies: 7
    Last Post: 5th August 2016, 07:06
  2. Replies: 2
    Last Post: 1st April 2011, 09:32
  3. How to use the clear buttom
    By levorn10 in forum Newbie
    Replies: 2
    Last Post: 7th January 2011, 08:00
  4. QListWidget - clear()
    By Carlsberg in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2010, 07:01
  5. QTreeWidget->clear()?
    By vishal.chauhan in forum Qt Programming
    Replies: 20
    Last Post: 5th October 2007, 07:00

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
  •  
Qt is a trademark of The Qt Company.