QTableWidget insertRow for values incoming in different time

时间:2015-07-28 16:27:04

标签: qt sockets insert row qtablewidget

I have an application which contains 10 QTCPSocket and all the time the sockets are receiving values from server. Values are received at different times. I want to store values in QTableWidget but I don't know when to call insertRow(). I try and add a row at the first socket update, but when the second socket data is received before the first it doesn't work.

I insert new row in first socket by:

ui->tableWidget->insertRow(ui->tableWidget->rowCount());
addItemToTable(0, value);

and the addItemToTable method:

void MainWindow::addItemToTable(int columnNumber, int value)
 {
     QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(value));
     ui->tableWidget->setItem(ui->tableWidget->rowCount()-1, columnNumber, newItem);
 }

This is the method for reading the socket data

void SocketManager::readData(QTcpSocket *socket) 
{ 
 QString str = socket->readAll(); int result = int(str.at(0).toLatin1());
 emit sendValue(result);
 }

0 个答案:

没有答案