Hello,

I have a QListWidget subclass which I use as a file browser. The list is filled using the setPath() function. My problem is that going through folders using the list shows an ever growing memory consumption in Windows Task Manager. Now I am using clear() at the beginning of the function and I expect that clear() does what it says in the docs: deletes all items in the list

Removes all items and selections in the view.

Note: All items will be permanently deleted.
This is the code
Qt Code:
  1. void BlaBla::setPath(const QString& path)
  2. {
  3. QFileIconProvider iconProvider;
  4.  
  5. m_path = path;
  6. m_dir = QDir(path);
  7.  
  8. clear();
  9. if (path == "My Computer")
  10. {
  11. for (int i = 0; i < m_dir.drives().size(); ++i)
  12. {
  13. QFileInfo info = m_dir.drives().at(i);
  14.  
  15. QString name;
  16. name.append(Globals::getVolumeInfo(info.filePath()).volumeName);
  17. name.append(" (");
  18. name.append(info.filePath().left(2));
  19. name.append(")");
  20. QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(info), name, this);
  21. item->setData(Qt::UserRole + 1, info.filePath());
  22. }
  23. }
  24. else
  25. {
  26. QFileInfo qInfo;
  27.  
  28. QString tempPath = m_dir.path() + QDir::separator();
  29.  
  30. if (m_dir.path() == QDir::home().absolutePath().append("/Desktop"))
  31. {
  32. QListWidgetItem* itemMyComputer = new QListWidgetItem(iconProvider.icon(QFileIconProvider::Computer), "My Computer", this);
  33. itemMyComputer->setData(Qt::UserRole + 1, "My Computer");
  34.  
  35. QListWidgetItem* itemMyDocuments = new QListWidgetItem(iconProvider.icon(QFileIconProvider::Folder), "My Documents", this);
  36. itemMyDocuments->setData(Qt::UserRole + 1, "My Documents");
  37. }
  38.  
  39. QList<FileInfo> theList = Globals::getFolderContens(m_dir.path().replace("/", "\\").append("\\*"), false);
  40. QList<FileInfo>::const_iterator i;
  41.  
  42. for (i = theList.begin(); i != theList.end(); ++i)
  43. {
  44. if ((*i).isDir)
  45. {
  46. QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(QFileIconProvider::Folder), (*i).name, this);
  47. item->setData(Qt::UserRole + 1, tempPath + (*i).name);
  48. }
  49. else
  50. {
  51. qInfo.setFile(m_dir.path() + QDir::separator() + (*i).name);
  52. QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(qInfo), (*i).name, this);
  53. item->setData(Qt::UserRole + 1, tempPath + (*i).name);
  54. }
  55. }
  56. }
  57. }
To copy to clipboard, switch view to plain text mode 

Am I doing something wrong?

I'm using Qt 4.5