Regarding Signals and Slots
-
void QTableWidget::cellChanged(int row, int column)
This signal is emitted whenever the data of the item in the cell specified by row and column has changed.
-
Ok. o.O
void MainWindow::on_tableWidget_itemChanged(QTableWidgetItem *item) { int numCols = ui->tableWidget->columnCount(); int numRows = ui->tableWidget->rowCount(); auto newValue = item->text(); for (int row = 0; row < numRows; ++row) { for (int col = 0; col < numCols ; ++col) { auto cellItem = ui->tableWidget->item(row, col); if (cellItem) cellItem->setText(newValue); } } }
-
Ok. o.O
void MainWindow::on_tableWidget_itemChanged(QTableWidgetItem *item) { int numCols = ui->tableWidget->columnCount(); int numRows = ui->tableWidget->rowCount(); auto newValue = item->text(); for (int row = 0; row < numRows; ++row) { for (int col = 0; col < numCols ; ++col) { auto cellItem = ui->tableWidget->item(row, col); if (cellItem) cellItem->setText(newValue); } } }
-
@mrjj I am using the same section of code which you have mentioned above, It is working. But before user changes the value in the tablewidget, it is filling with some garbage value. Please let me know,what is the issue? Our changes is interfering with the insertion step itself. How to avoid this?
-
@mrjj I am using the same section of code which you have mentioned above, It is working. But before user changes the value in the tablewidget, it is filling with some garbage value. Please let me know,what is the issue? Our changes is interfering with the insertion step itself. How to avoid this?
@Shruthi
HI
I think the signal will also trigger when you fill the table.To avoid that.
Either fill the table BEFORE you connect the signal.or block its signals while filling it
https://doc.qt.io/qt-5/qsignalblocker.html -
@Shruthi
HI
I think the signal will also trigger when you fill the table.To avoid that.
Either fill the table BEFORE you connect the signal.or block its signals while filling it
https://doc.qt.io/qt-5/qsignalblocker.html -
Hi
if the goal is to block signals then as jonB says you must doui->tableWidget->blockSignals(true);
xxxxx
ui->tableWidget->blockSignals(false);not reverse
-
@Shruthi
So your slot is firing while you are initialising. You have a couple of choices:-
Here you also want to block signals during
fillTableWidget(), so add that; or -
Do not
connect()the slot till afterfillTableWidget()has done its work. If you are using Designer's autoconnect of slots change over to your own connects.
-
-
Just one question - what should fillTableWidget() do at all (apart from the fact that it does not compile at all)? When rowCount() is greater than 0 then empty QTableWidgetItem's are set, nothing more.
Please provide a minimal, compilable example to reproduce your issue!
-
@Shruthi
So your slot is firing while you are initialising. You have a couple of choices:-
Here you also want to block signals during
fillTableWidget(), so add that; or -
Do not
connect()the slot till afterfillTableWidget()has done its work. If you are using Designer's autoconnect of slots change over to your own connects.
-