Good afternoon, there is a table in tabeWidget from its row trying to get a copy of the second tabeWidget_2 with this construct

ui->tableWidget_2->setItem(1,1, item); 

but an error pops up in the console

QTableWidget: cannot insert an item that is already owned by another QTableWidget

  • Do you want this line to "move" to another table or a copy appears there? - KoVadim
  • @KoVadim appeared copy. - Varg Sieg

1 answer 1

The error is absolutely expected - the item cannot be "the servant of two masters" - it must have one parent. And you are trying to add it immediately in two. and item is just a pointer. You need to make a copy automatically (and the clone function will help with this) or pens (creating a new QTableWidgetItem and filling it with data).

Therefore, most likely this should work.

 ui->tableWidget_2->setItem(1,1, item->clone());