Regarding Signals and Slots
-
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.
-
-
Again: your code does not even compile so how did you check it? What should your function do at all? And on_tableWidget_singleitemchanged() also crashes when there is at least one row.
Provide a fully, minimal compilable example!
-
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!
@Christian-Ehrlicher It will compile and it fills the tablewidget with values. But the signal is not triggering correctly when user typed some value to the tablewidget.
Please check only the signal and slot and let me know, if I have missed anything in that.
Thank you. -
@Shruthi said in Regarding Signals and Slots:
s1 =->setTextAlignment(Qt::AlignCenter);
No, this does not compile!
it fills the tablewidget with values
No, it does not - you don't set a text to any of those QTableWidgetItems... provide compilable code!
-
@Shruthi said in Regarding Signals and Slots:
void gen_window::on_tableWidget_singleitemchanged( )You have made the slot a member of
gen_window.connect(ui->tableWidget,SIGNAL(itemChanged()),this,SLOT(on_tableWidget_singleitemchanged()));You connect to it as a member of
this, which isMainWindow.Why do that I don't know. But if you used new signal & slot connection syntax, as I say to everyone, you would have known immediately. If you must use old style, check return result from
connect()s and allow for runtime errors. -
Hi
there is something wrong with slot and connect
its
void QTableWidget::itemChanged(QTableWidgetItem *item)so connect is wrong as the parameter is not included
connect(ui->tableWidget,SIGNAL(itemChanged(QTableWidgetItem *)),this,SLOT(on_tableWidget_singleitemchanged(QTableWidgetItem *)));
(using the new syntax is far better )and your slot is also not on the spot
void gen_window::on_tableWidget_singleitemchanged( )
{
QTableWidgetItem *item; <<< this is bad as danglining pointer. item should be the parameterso its
void gen_window::on_tableWidget_singleitemchanged(QTableWidgetItem *item )
{
QTableWidgetItem *item;