QTreeWidgetItemIterator craches.
-
@QTreeWidgetItemIterator it( item );@
This line crashes whole app. Item is a valid topLevelItem of a QTreeWidget.
What could be wrong? -
"item" is a QTreeWidget instance and "it" is the iterator , right ?
-
Sorry i did not provide this part of code:
@QTreeWidget* tw;
// ... initialization of tw ...
QTreeWidgetItem* item = tw->topLevelItem( 0 )->clone();@ -
@topLevelItem(0)@ returns 0 if the item does not exist. May be its a good idea, you check that before you instanciate.
-
I did check. More than that, QTreeWidget constructed with "item" as a top level item is displayed normally.
-
I meant a check in code.. @while(QTreeWidgetItem *item = tw->topLevelItem(0)){
....
}@
[quote author="p-himik" date="1316932916"]I did check. More than that, QTreeWidget constructed with "item" as a top level item is displayed normally.[/quote]Am Just curious, is it necessary to create deep copy of the item ?
-
I think so. I have a parent window with a tree of categories and images and a dialog for adding images to particular category. In this dialog i create QTreeWidget with only categories by cloning QTreeWidget from parent window and removing image items.
-
Sounds like you need to use real model/view instead of the *widget version... If you go about cloning the tree to display it in another window, you are on the wrong road, if you ask me.
Instead, you could considder using a QStandardItemModel (API is similar to QTreeWidget and -Item), replace the QTreeWidget with a QTreeView and use a QSortFilterProxyModel to filter out the unwanted items from the model for display on the second window.
-
I don't know well MVC-part of Qt and this is rather simple application so i decided just to copy items.
But what about QTreeWidgetItemIterator? Why can it crash when passed parameter is valid?
-
one reason could be improper initialization. But you are so sure about it.
-
[quote author="p-himik" date="1316950625"]I don't know well MVC-part of Qt and this is rather simple application so i decided just to copy items.
But what about QTreeWidgetItemIterator? Why can it crash when passed parameter is valid?[/quote]
If you show us more code, we could perhaps help you, but if we only get one or two lines, we have to gess the rest, which is not very easy.
-
Here is a short example: http://dl.dropbox.com/u/26596688/testProject.tar.gz