Calculate clicks
-
Hi!
How I can programmer, that when I click pushbutton first time, listwidget says "Hello!" and when I click second time listwidget says "What's up?". Or first time: "Hello" and second time: listwidget clear empty itself.
I've tried with int and char and everything. I've looked at the docs, but nothing. I don't still know that.I want, that when 5-10 lines are finished, next click will skip them.
@void Words::on_pushButton_2_clicked()
{
int Time = 1;
const char* S1 = "a dog";
const char* S2 = "a cat";
if (S1 == ui->lineEdit->text() && Time == 1)
{
ui->listWidget->addItem("RIGHT");
Time = Time + 1;
}
if (S2 == ui->lineEdit->text() && Time == 2)
{
ui->listWidget->addItem("RIGHT");
Time = Time + 1;
}
if ((!(S1 == ui->lineEdit->text()) && Time == 1) && !(S2 == ui->lineEdit->text() && Time == 2))
{
ui->listWidget->addItem("WRONG! Try again.");
}
}@Do you understand what I mean? Ask if you don't, I will explain.
Thanks for answers! -
You have a lot of problems in your code.
On first look, it should be something like:
@void Words::on_pushButton_2_clicked()
{
static int Time = 1;
QString S1 = "a dog";
QString S2 = "a cat";if ((!(S1 == ui->lineEdit->text()) && Time == 1) && !(S2 == ui->lineEdit->text() && Time == 2)) { ui->listWidget->addItem("WRONG! Try again."); return; } if (S1 == ui->lineEdit->text() && Time == 1) { ui->listWidget->addItem("RIGHT"); } if (S2 == ui->lineEdit->text() && Time == 2) { ui->listWidget->addItem("RIGHT"); } Time = Time + 1;
}@
-
Yes!
Thank you very much!
Fast and simple reply! I think "static" was the answer I looked for.
Thanks! That helps me really much!