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

Kevin Funk kfunk at kde.org
Wed Apr 26 11:24:06 CEST 2017

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 
    item = 0;

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

Is that the case for you?

Hope that helps,

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/
> 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/e342a7a7/attachment.sig>

More information about the Interest mailing list