QTreeWidget::clear() does clear the tree immediately. Do you give it a chance to update itself?
QTreeWidget::clear() does clear the tree immediately. Do you give it a chance to update itself?
J-P Nurmi
Thanks for reply.
Actually what I want is that I have a LinkList of Items which I m showing in QTreeWidget.
So when I double click a item in the treeWidget I m clearing a tree and showing the child of that QTreeWidgetItem which are in Linked List.
But as QtreeWidget->clear() takes some time to clear a treeWidget if I emit the signal to show its child then it get crashed.
So I want that once the treeWidget is cleared then i emit the signal to add new item on the same tree.
and the application crashes only when i am clearing the treeWidget.
Aren't you using currentItem(which is NULL after clear()) in method that adds new item?
To me it sounds like you end up having a bunch of invalid pointers in your external linked list structure. Notice that QTreeWidget::clear() deletes items. Use QTreeWidget::takeTopLevelItem(), QTreeWidgetItem::takeChild() or such for taking items out of QTreeWidget without deleting them.
J-P Nurmi
Hi.......
But If we UseQt Code:
To copy to clipboard, switch view to plain text mode
then it removes that items only that are inserted at the index we are passing , not all the items that are in the QTreeWidget.
Thanx
Always Believe in Urself![]()
Merry
So what's the problem? Take them all one by one:
Qt Code:
while (treeWidget->topLevelItemCount() > 0) treeWidget->takeTopLevelItem(0);To copy to clipboard, switch view to plain text mode
PS. If I were you, I'd rather switch to model-view approach which is way more flexible in situations like this..
J-P Nurmi
Using this , When I double click on treeWidgetItem then also , program crashes
Qt Code:
while (treeWidget->topLevelItemCount() > 0) treeWidget->takeTopLevelItem(0);To copy to clipboard, switch view to plain text mode
Thanx
Always Believe in Urself![]()
Merry
So build the app in debug mode, run it via debugger and see the backtrace to see where exactly it crashes. Otherwise all we can do is to keep guessing for the rest of the month.
J-P Nurmi
Thanx for the reply
Yaa u are right ,
Actually , at the time when I double click on the treeWidgetItem to show only its contents and deletes all other , then it Crashes , Otherwise , if i wont clear the treeWidget , then It dont crashes.
There is a problem , in clearing the tree.
Thanx
Always Believe in Urself![]()
Merry
Hi,
I think you read the data for the tree from a table ( in a database ). is it?
if so, first you create a connection with the tree like this
connect( ManagerTree, SIGNAL( itemDoubleClicked (QTreeWidgetItem*,int) ), this, SLOT( ChkTreeItem(QTreeWidgetItem*, int ) ) );
and you write a function for create the tree passing the frst level of the item.
After that, you create another function named as ChkTreeItem(QTreeWidgetItem*, int ) and in that function you read the text item like this
QString Name = item->text(column);
Then you get the selected item from the variable Name. Using this Variable you can get the level of the item from the table.
Then you clear the tree. after you recall the first function with the level.
I think through this methord you can solve your probs.
Try it.....![]()
For database data you would use one of available SQL models depending on your needs, and a view:
Qt Code:
model->setQuery("SELECT * FROM table"); view->setModel(model);To copy to clipboard, switch view to plain text mode
J-P Nurmi
Thanx for the reply
But I am not using database to store items , I am creating linklist for the items , I also made a connection
Qt Code:
connect(TreeWidgetFolder,SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(ShowTreeWidgetFolderItem( QTreeWidgetItem *, int) ));To copy to clipboard, switch view to plain text mode
regards
Always Believe in Urself![]()
Merry
Bookmarks