You are dead right as my follow up email confirms.
Now the question is how to use the same (parented) item in a tree view and a list view.
I guess I will be RTFM-ing a bit.

Cheers,
frank


On 26/04/17 9:24 PM, Kevin Funk wrote:
On Wednesday, 26 April 2017 19:50:54 CEST Frank Rueter | OHUfx wrote:
Hi,

I seem to run into this issue a lot and I don't get why:
I have a list of sub-classed QStandardItems that another processor
generated, and I want to add them to a QStandardItemModel like this:

for item in myItemList:
      self.model.appendRow(item)

The model is empty and hasn't been used at this point. Yet I get none of
my items but one of those errors for each item:
      QStandardItem::insertRows: Ignoring duplicate insertion of item
Use the source, Luke :)

QStandardItemModel::appendRow calls
- QStandardItem::appendRow which calls
- QStandardItem::insertRow which calls
- QStandardItemPrivate::insertRows [1]

Excerpt from QStandardItemPrivate::insertRows:
```
//...
if (item->d_func()->parent == 0) {
     item->d_func()->setParentAndModel(q, model);
} else {
     qWarning("QStandardItem::insertRows: Ignoring duplicate insertion of item
%p",
              item);
     item = 0;
}
//...
```

=> The warning is thrown when your items already have a parent set

Is that the case for you?

Hope that helps,
Kevin

PS: The Woboq code browser is an awesome tool to follow call chains (or any
decent IDE will do, if you have the Qt sources)

[1] https://code.woboq.org/qt5/qtbase/src/gui/itemmodels/
qstandarditemmodel.cpp.html#_ZN20QStandardItemPrivate10insertRowsEiiRK5QListIP13QStandardItemE
I know I should know this but I can't figure out why this is happening.
Is there something special I need to do when subclassing QStandardItem?


Cheers,
frank


_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to