PDA

View Full Version : Copying row from one table to another



ser_bur
29th May 2007, 15:05
Hi, All!
I think I need some advice... I want to copy row from one QTableWidget to another. The first idea was to copy cell-by-cell, something like this:



QTableWidgetItem Table2Item[Table1->columnCount()];
for(j=0;j<(Table1->columnCount());j++)
{
Table2Item[j] = *Table1->item(Table1->currentRow(),j);
Table2->setItem(Table2->currentRow(),j,&Table2Item[j]);
}


But this just inserts an empty row into Table2... I think I made a stupid mistake, but I do not see where... Maybe there is another way to copy the row? :confused:

marcel
29th May 2007, 15:12
Hint: use the copy constructor of QTableWidgetItem (http://doc.trolltech.com/latest/qtablewidgetitem.html) and copy the item directly, not cell by cell.

Your solution doesn't work because you're trying to add an item that is owned by the other table.

Regards

ser_bur
29th May 2007, 15:25
YESS!! It works. Why right solution never comes itself? :)
Thanks!