Carlsberg
2nd June 2010, 12:22
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
void BlaBla::setPath(const QString& path)
{
QFileIconProvider iconProvider;
m_path = path;
m_dir = QDir(path);
clear();
if (path == "My Computer")
{
for (int i = 0; i < m_dir.drives().size(); ++i)
{
QFileInfo info = m_dir.drives().at(i);
QString name;
name.append(Globals::getVolumeInfo(info.filePath() ).volumeName);
name.append(" (");
name.append(info.filePath().left(2));
name.append(")");
QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(info), name, this);
item->setData(Qt::UserRole + 1, info.filePath());
}
}
else
{
QFileInfo qInfo;
QString tempPath = m_dir.path() + QDir::separator();
if (m_dir.path() == QDir::home().absolutePath().append("/Desktop"))
{
QListWidgetItem* itemMyComputer = new QListWidgetItem(iconProvider.icon(QFileIconProvide r::Computer), "My Computer", this);
itemMyComputer->setData(Qt::UserRole + 1, "My Computer");
QListWidgetItem* itemMyDocuments = new QListWidgetItem(iconProvider.icon(QFileIconProvide r::Folder), "My Documents", this);
itemMyDocuments->setData(Qt::UserRole + 1, "My Documents");
}
QList<FileInfo> theList = Globals::getFolderContens(m_dir.path().replace("/", "\\").append("\\*"), false);
QList<FileInfo>::const_iterator i;
for (i = theList.begin(); i != theList.end(); ++i)
{
if ((*i).isDir)
{
QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(QFileIconProvide r::Folder), (*i).name, this);
item->setData(Qt::UserRole + 1, tempPath + (*i).name);
}
else
{
qInfo.setFile(m_dir.path() + QDir::separator() + (*i).name);
QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(qInfo), (*i).name, this);
item->setData(Qt::UserRole + 1, tempPath + (*i).name);
}
}
}
}
Am I doing something wrong?
I'm using Qt 4.5
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
void BlaBla::setPath(const QString& path)
{
QFileIconProvider iconProvider;
m_path = path;
m_dir = QDir(path);
clear();
if (path == "My Computer")
{
for (int i = 0; i < m_dir.drives().size(); ++i)
{
QFileInfo info = m_dir.drives().at(i);
QString name;
name.append(Globals::getVolumeInfo(info.filePath() ).volumeName);
name.append(" (");
name.append(info.filePath().left(2));
name.append(")");
QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(info), name, this);
item->setData(Qt::UserRole + 1, info.filePath());
}
}
else
{
QFileInfo qInfo;
QString tempPath = m_dir.path() + QDir::separator();
if (m_dir.path() == QDir::home().absolutePath().append("/Desktop"))
{
QListWidgetItem* itemMyComputer = new QListWidgetItem(iconProvider.icon(QFileIconProvide r::Computer), "My Computer", this);
itemMyComputer->setData(Qt::UserRole + 1, "My Computer");
QListWidgetItem* itemMyDocuments = new QListWidgetItem(iconProvider.icon(QFileIconProvide r::Folder), "My Documents", this);
itemMyDocuments->setData(Qt::UserRole + 1, "My Documents");
}
QList<FileInfo> theList = Globals::getFolderContens(m_dir.path().replace("/", "\\").append("\\*"), false);
QList<FileInfo>::const_iterator i;
for (i = theList.begin(); i != theList.end(); ++i)
{
if ((*i).isDir)
{
QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(QFileIconProvide r::Folder), (*i).name, this);
item->setData(Qt::UserRole + 1, tempPath + (*i).name);
}
else
{
qInfo.setFile(m_dir.path() + QDir::separator() + (*i).name);
QListWidgetItem* item = new QListWidgetItem(iconProvider.icon(qInfo), (*i).name, this);
item->setData(Qt::UserRole + 1, tempPath + (*i).name);
}
}
}
}
Am I doing something wrong?
I'm using Qt 4.5