Hi, I want to subclass QTreeWidgetItem and use it within a QTreeWidget subclass, but I do not want to reimplement all functions from QTreeWidgetItem nore QTreeWidget.
So far so god.
Additionally I need the option to dynamically update the TreeWidget.
I create a method to search for applicable TreeWidgetItems:
/*! search from root (if root is zer0, search all nodes) all children for the Desired Drawable
*/
TreeWidgetItem* TreeWidget::deepSearchByPtr(TreeWidgetItem *root, Drawable *d){
qDebug() << "DFS 0";
if (root == 0){
}
else if (reinterpret_cast<Drawable*>(root->ptr()) == d){
qDebug() << "DFS B";
return root;
}
qDebug() << "DFS C";
TreeWidgetItem *ret;
TreeWidgetItem *child;
qDebug() << "DFS D";
int count(0);
if (root==0){
count = invisibleRootItem()->childCount();
}
else{
count = root->childCount();
}
for(int q(0); q<count; ++q){
qDebug() << "DFS LOOP A";
child = reinterpret_cast<TreeWidgetItem*>(root->child(q));
qDebug() << "DFS LOOP B";
if (child == NULL){
qDebug() << "DFS LOOP C";
continue;
}
qDebug() << "DFS LOOP D";
ret = deepSearchByPtr(child, d);
qDebug() << "DFS LOOP E";
if (ret != NULL){
qDebug() << "DFS LOOP F";
return ret;
}
}
return NULL;
}
/*! search from root (if root is zer0, search all nodes) all children for the Desired Drawable
*/
TreeWidgetItem* TreeWidget::deepSearchByPtr(TreeWidgetItem *root, Drawable *d){
qDebug() << "DFS 0";
if (root == 0){
}
else if (reinterpret_cast<Drawable*>(root->ptr()) == d){
qDebug() << "DFS B";
return root;
}
qDebug() << "DFS C";
TreeWidgetItem *ret;
TreeWidgetItem *child;
qDebug() << "DFS D";
int count(0);
if (root==0){
count = invisibleRootItem()->childCount();
}
else{
count = root->childCount();
}
for(int q(0); q<count; ++q){
qDebug() << "DFS LOOP A";
child = reinterpret_cast<TreeWidgetItem*>(root->child(q));
qDebug() << "DFS LOOP B";
if (child == NULL){
qDebug() << "DFS LOOP C";
continue;
}
qDebug() << "DFS LOOP D";
ret = deepSearchByPtr(child, d);
qDebug() << "DFS LOOP E";
if (ret != NULL){
qDebug() << "DFS LOOP F";
return ret;
}
}
return NULL;
}
To copy to clipboard, switch view to plain text mode
The Problem with that is, that it fails right before
qDebug() << "DFS LOOP B";
qDebug() << "DFS LOOP B";
To copy to clipboard, switch view to plain text mode
though all children actually are TreeWidgetItem s.
Note: falling back to QTreeWidgetItems is not an option, as they hold way more data than ptr.
Note:
My Custom Type is called "TreeWidgetItem" and "TreeWIdget"
can anybody plx help me to fix this issue.
Sincerely
soxs060389
P.S. allready wasted hours on that subject...
Bookmarks