My program should gradually output the results of calculations in the table cells. There is a window (implemented as an object of the Widget class inherited from QWidget), this object has a property r_table (pointer to QTableWidget) - this is the table itself.
How many lines you need is not known in advance, so I want them added as needed.
I need a method
void Widget::setTableValue(int i, int j, double value) which puts the number value in the cell with row number i and column number j , and if there is no row i , it creates it.
How to implement this?
I tried to do it like this
void Widget::setTableValue(int i, int j, double value) { while (r_table->rowCount() < i) r_table->insertRow(r_table->rowCount()); r_table->setItem(i, j, new QTableWidgetItem(QString::number(value, 'g', 2))); } but it fills the table like it is.
QTableWidgetis a toy ... for any task more difficult than the most primitive display of several lines in a table, IMHO it’s better to use a normal model withQTableView... but it will take some time to study the framework and refuse bad habits ... - Fat-Zer