I have 2 push button, one for increment & the other for decrement & a label to display result. I use this setup in 2 different places. But in some odd cases, the counter seems to be increasing at the rate of 16(0,16,32..etc). I'm not sure why this is happening. What am i doing wrong here. Is there an easier/simple way of doing this?
int count2; (declared in a .h file, as a public variable)
connect(this->ui->pb_inc, SIGNAL(clicked()), this, SLOT(inc()));
connect(this->ui->pb_dec, SIGNAL(clicked()), this, SLOT(dec()));
void MainWindow::inc()
{
count2=count2+1;
this
->ui
->label_count
->setText
(QString("%1").
arg(count2
));
}
void MainWindow::dec()
{
count2=count2-1;
if(count2<=0) count2=0;
this
->ui
->label_count
->setText
(QString("%1").
arg(count2
));
}
int count2; (declared in a .h file, as a public variable)
connect(this->ui->pb_inc, SIGNAL(clicked()), this, SLOT(inc()));
connect(this->ui->pb_dec, SIGNAL(clicked()), this, SLOT(dec()));
void MainWindow::inc()
{
count2=count2+1;
this->ui->label_count->setText(QString("%1").arg(count2));
}
void MainWindow::dec()
{
count2=count2-1;
if(count2<=0) count2=0;
this->ui->label_count->setText(QString("%1").arg(count2));
}
To copy to clipboard, switch view to plain text mode
Bookmarks