OK. Now I have the tree created using the above referenced code. And I figured out how to traverse it. Problem is when I try to print the data from the node I get nothing. Just the “method: “ portion.
Where did I go wrong??
Also when the lower node is “checked†what kinf of even is generated? I want to be able to do some processing when that occurs.
Thanks, again
void CTREEcu::processTree()
{
// loop through all branches and nodes of the tree and diaplay its text
for ( int i=0; i< twMain->topLevelItemCount(); i++)
{
qDebug("PARENT - idx: %d text: %s",i,qPrintable(item->text(0)));
processItem(item);
}
}
{
for (int i=0; i< parent->childCount(); i++)
{
qDebug("CHILD - idx: %d text: %s",i,qPrintable(child->text(0)));
if ( child->checkState(0) == Qt::Checked )
{
qDebug("CHILD - THIS ONE IS CHECKED");
child->setCheckState(0,Qt::Unchecked);
// this piece of code can be used to set a marker for the current checked
// item so it is not erased
qDebug("internalId: %ld",idx.internalId());
// print out sample data
QMap<QString,QVariant> nodeData = child->data(0,Qt::UserRole).toMap();
qDebug("method: %s",qPrintable(nodeData.value("method").toString()));
}
processItem(child);
}
}
void CTREEcu::processTree()
{
// loop through all branches and nodes of the tree and diaplay its text
for ( int i=0; i< twMain->topLevelItemCount(); i++)
{
QTreeWidgetItem *item = twMain->topLevelItem(i);
qDebug("PARENT - idx: %d text: %s",i,qPrintable(item->text(0)));
processItem(item);
}
}
void CTREEcu::processItem(QTreeWidgetItem * parent)
{
for (int i=0; i< parent->childCount(); i++)
{
QTreeWidgetItem *child = parent->child(i);
qDebug("CHILD - idx: %d text: %s",i,qPrintable(child->text(0)));
if ( child->checkState(0) == Qt::Checked )
{
qDebug("CHILD - THIS ONE IS CHECKED");
child->setCheckState(0,Qt::Unchecked);
// this piece of code can be used to set a marker for the current checked
// item so it is not erased
QModelIndex idx = twMain->currentIndex();
qDebug("internalId: %ld",idx.internalId());
// print out sample data
QMap<QString,QVariant> nodeData = child->data(0,Qt::UserRole).toMap();
qDebug("method: %s",qPrintable(nodeData.value("method").toString()));
}
processItem(child);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks