PDA

View Full Version : Problem inserting in QTableWidget



DPinLV
31st July 2006, 22:57
Hi All,

I have a QTableWidget that I add rows during runtime using the following type of code:


bool QTClient::addToTable (int id, int lobby_view, QString name)
{
int column = 0;

ui.m_TableWidget->insertRow(ui.m_TableWidget->rowCount ());

QTableWidgetItem* tbl_item = new QTableWidgetItem (QString::number(id));
ui.m_TableWidget->setItem ( location_index, column++, tbl_item );

tbl_item = new QTableWidgetItem (QTableWidgetItem (QString::number(lobby_view)));
ui.m_TableWidget->setItem ( location_index, column++, tbl_item );

tbl_item = new QTableWidgetItem (QTableWidgetItem (name));
ui.m_TableWidget->setItem ( location_index, column++, tbl_item );

ui.m_holdemAllTableWidget->update ();
}


I have a button on my window that calls this code when pressed and the new line is added and displayed just fine in the table.

However, the problem comes when this add method is called from a thread.
When my thread fires it also calls the addTable method, but the data does not show up on the screen. The row count on the table increases, but the new data does not display.

Does anyone have any ideas why I can not see data added to my table from a thread?

Thanks in advance,
Derrick

jacek
31st July 2006, 23:04
Does anyone have any ideas why I can not see data added to my table from a thread?
You can't invoke widget methods from a non-GUI thread (see here (http://doc.trolltech.com/4.1/threads.html#qobject-reentrancy)). To do it the right way, you have to turn addToTable() into a slot and use a queued connection.

DPinLV
2nd August 2006, 00:10
Jacek,

That explains a lot... I've been doing some more research and I'll be making another posting because my signal slot works using a simple type (i.e. int, QString, etc.), but the connect call fails when I pass my custom struct. :)

Thanks,
Derrick