PDA

View Full Version : QTreeWidgetItem



bismitapadhy
10th February 2010, 05:36
In QTreeWidgetItem, it is storing all data in heap memory. After filling more data performance becoming slow. Any solution for this.

aamer4yu
10th February 2010, 06:09
How much data are you saving ? May using model would be a better way

bismitapadhy
10th February 2010, 06:18
Storing more data,result of 10,000 testcase, in this condition on run time result node is adiing to the explorer window. So after completion of 20% result node added, when i am double clicking on that node it is taking more time to open, performance becoming slower. Mouse also moving slow in the explorer window.

aamer4yu
10th February 2010, 09:45
10000 entries in a single QTreeWidgetItem ??
Or are you creating 10000 QTreeWidgetItem objects ?

bismitapadhy
10th February 2010, 09:56
I uploaded the image, as like testcase 1, 2, there are 10,000/-.On run time result node add to each one. So after completion of 20% execution it is taking time to open the result node as well as it is taking time to scroll the scroll bar.

aamer4yu
10th February 2010, 11:14
How are you adding the items into the treewidgets ? Need some code to identify the bottleneck.
As far as I see, the 10000 number of items is slowing the process. It would be better if you use model and view instead of the QTreeWidget.

bismitapadhy
10th February 2010, 11:24
if (m_testSeqFileName.isEmpty())
{
SmartMsg::Info(tr("Create Test Sequence File from the Script Sequence File"));
return; //TODO: is this required.
}
else
{
m_pTestSeqFileNode = new QTreeWidgetItem(m_pProjRoot);
m_pTestSeqFileNode->setText(0,m_testSeqFileName);
m_pTestSeqFileNode->setData(0,Qt::AccessibleDescriptionRole, e_TST_SEQFILE);

// QFont font = tstSeqFileNode->font(0);
// font.setBold(true);
// tstSeqFileNode->setFont(0,font);
// m_pEditor->open(m_projectFolder + QDir::separator() + m_testSeqFileName);
}

QStringList tstFolderList;

for(int tcCount = 0; tcCount < m_testcaseFiles.size(); tcCount++)
{
QString testcaseFilePath = m_testcaseFiles[tcCount];
QTreeWidgetItem * tstFileNode;

if (testcaseFilePath.contains(QDir::separator()) || testcaseFilePath.contains('/'))
{
QChar separator;
if (testcaseFilePath.contains(QDir::separator()))
{
separator = QDir::separator();
}
else
{
separator = '/';
}

int leftPart = testcaseFilePath.indexOf(separator);
int rightPart = testcaseFilePath.length()-leftPart-1;

QString testcaseFolder = testcaseFilePath.left(leftPart);
QTreeWidgetItem * tstFolderNode;

bool isFolderNodeExists = false;

for (int i = 0; i < m_testCaseFolderList.count(); i++)
{
if (m_testCaseFolderList[i]->text(0) == testcaseFolder)
{
isFolderNodeExists = true;
break;
}
}

if (!isFolderNodeExists)
{
tstFolderNode = new QTreeWidgetItem(m_pProjRoot);
tstFolderList.append(testcaseFolder);
tstFolderNode->setText(0, testcaseFolder);
tstFolderNode->setData(0,Qt::AccessibleDescriptionRole, e_FOLDER);
m_testCaseFolderList.append(tstFolderNode);
}

QString testcaseFile = testcaseFilePath.right(rightPart);

// if(tstFolderNode != NULL) // fixed crash
// {
tstFileNode = new QTreeWidgetItem(tstFolderNode);
tstFileNode->setText(0, testcaseFile);
tstFileNode->setData(0,Qt::AccessibleDescriptionRole,e_SCRFILE) ;
m_pProjExpTreeWidget->expandItem(tstFolderNode);
// }
}
else
{
tstFileNode = new QTreeWidgetItem(m_pProjRoot);
tstFileNode->setText(0, testcaseFilePath);
tstFileNode->setData(0,Qt::AccessibleDescriptionRole,e_SCRFILE) ;
m_testCaseFolderList.append(tstFileNode);
}

QStringList testCaseIDs = m_mapTestcaseFileToIDs[testcaseFilePath];

for (int i = 0; i < testCaseIDs.size(); ++i)
{
QTreeWidgetItem * testIDNode = new QTreeWidgetItem(tstFileNode);
testIDNode->setText(0, testCaseIDs[i]);
}
m_pProjExpTreeWidget->expandItem(tstFileNode);
}
m_pProjExpTreeWidget->expandItem(m_pProjRoot);

ecanela
11th February 2010, 01:10
10,000 QTreeWidgetItem consume a lot memory and procesor.

i think is better approach use a custom model and a QTreeView. this way can implement stuff like lazy population to reduce the memory usage and other optimizations

QTreeWidet is the best choice when only need create simple hierarchical lists. and manage 10,000 item is not a simple case.

bismitapadhy
15th February 2010, 06:32
Can you send me a example of this.

franz
15th February 2010, 06:36
http://doc.trolltech.com/4.6/model-view-programming.html

bismitapadhy
17th February 2010, 04:24
I saw QTreeview class but i didn't found anything to add a child of Qtreeview in the runtime. Please let me know is there is any possibility of add a child to the QTreeview dynamically?

ecanela
17th February 2010, 05:30
you dont need reimplement the QTreeView class.
you need implement a custom model, and then usiing the model in the QTreeView. this way the lazy population and are in the model not in the view.

create a custom model is not a easy task, one must take atention to several details. check http://doc.trolltech.com/4.6/model-view-model-subclassing.html to more info. alsp the Qt example Simple Tree Model http://doc.trolltech.com/4.6/itemviews-simpletreemodel.html

another tip, check in the source code the implementation of QStringListModel, in my case i found the implemetation of this class very useful. in my system is located in C:/Qt/2009.05/qt/src/gui/itemviews.

helmuth
7th January 2011, 10:48
anyone else here thinking Qts mvc is utter crap?

thinking of item views i'd say every byte shifted around less counts. so lets tack some fashnionable design paradigms on top of it to make it real fast.. FAIL.