[Interest] I feel stupid: QStandardItem::insertRows: Ignoring duplicate insertion of item

Kevin Funk kfunk at kde.org
Wed Apr 26 17:47:42 CEST 2017


On Wednesday, 26 April 2017 21:32:13 CEST Frank Rueter | OHUfx wrote:
> 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.

That's discussed over here:
  http://stackoverflow.com/questions/19498753/append-qstandarditem-in-two-qstandarditemmodel-at-the-same-time

You might want to start writing a proper model (QAbstractItemModel based) 
instead. Or you'll need to create copies of the QStandardItems (which is 
probably undesired as you manually need to keep them in sync if needed).

Hope that helps,
Kevin

> 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#_ZN20QStandardItemPrivate10insertRowsEiiRK5QLi
> > stIP13QStandardItemE> 
> >> 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


-- 
Kevin Funk | kfunk at kde.org | http://kfunk.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 163 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170426/3f02c1bb/attachment.sig>


More information about the Interest mailing list