[Qt-interest] setText on a QTableWidgetItem as no effect

Gianluca Montecchi gian at grys.it
Mon Nov 23 16:25:32 CET 2009


Hi.
I am having a strange problem where I try to change the text or a 
QTableWidgetItem.

The gui is created with QtDesigner and I put a QTableWidget with tow columns
and some row. The items are created and have some default values (say 0).

At some point in my software, I have a SLOT that need to change some values in
the QTableWidget, the implementation is:

--- 
void BulbCalculator::Test() {

    QTableWidgetItem *curItem;

    curItem = this->TW_BULB->item(0,0);
    qDebug() << curItem->text();
    curItem->setText(QString("Test"));
    qDebug() << curItem->text();
    this->TW_BULB->setItem(0,0,curItem);

}
---

The slot is called, since I can see the two qDebug output. I think that I 
get the item correctly, since the output show the right values before and 
after the setText call.
Anyway, the cell is not updated and I get the warning:

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

If I comment out the setText call, I get no warning, but the cell still does
not change the text, it seems that the QTableWidget get not updated, since the
item has always the right value.

Any hints ?

Thanks
bye
Gianluca



More information about the Qt-interest-old mailing list