PDA

View Full Version : check whether a row is filled with values in tablewidget and fill values in new row



kulsekarr
26th November 2014, 06:55
hi i am trying to get the inputs from 4 line edit widgets and paste it into table-widgets & also able to fill the first row in table .
can any one help me out how to check whether the first row is filled and if it is filled how to add the data s in the next consecutive rows one by one in table widget

Any one can suggest me some solutions.


Thanks in advance



void Widget::on_pushButton_Add_clicked()
{


ui->tableWidget->setItem(0, 0, new QTableWidgetItem(ui->lineEdit_UDPport->text()));
ui->tableWidget->setItem(0, 1, new QTableWidgetItem(ui->lineEdit_DataName->text()));
ui->tableWidget->setItem(0, 2, new QTableWidgetItem(ui->lineEdit_DataAddress->text()));
ui->tableWidget->setItem(0, 3, new QTableWidgetItem(ui->comboBox_DataType->currentText()));
ui->tableWidget->setItem(0, 4, new QTableWidgetItem(ui->lineEdit_DataLength->text()));

}

anda_skoa
26th November 2014, 09:20
Do you start with an empty table or with a table with one empty row?

Cheers,
_

kulsekarr
26th November 2014, 09:30
Thanks for your reply . by default i have fixed the size for the table with 10 Rows and 5 columns in the UI

anda_skoa
26th November 2014, 13:50
Then you need to keep track which row is the next empty one and then use this to call setItem().
if the next row is == rowCount() then add a new row

Cheers,
_

kulsekarr
27th November 2014, 09:37
hi thanks, the code which i have pasted in the first thread will copy the contents from different line edits(inputs) after clicking the push button it copies and paste it in the first row of the table widget.
and when i try to give the input in different line edit boxes once again it must be pasted in the second row of the table widget. it is not happening. please do help me out

the size of the table widget is fixed in the UI form as 10 rows and 5 columns

anda_skoa
27th November 2014, 10:15
Well, your current code specifies row 0, you obviously need to make that a variable that you increase when you've added a row.

Cheers,
_