B
B
Blunker2016-06-19 18:47:51
Qt
Blunker, 2016-06-19 18:47:51

How to increment a counter in qt?

There is a code

int page = 0;
    int count = 2;


    if (ui->lineEdit->text().toDouble() == answers[page].getA())
    {
        ui->textBrowser_2->clear();
        ui->textBrowser_2->append(tasks[page+1]);
        QString str = QString::number(count);
        ui->label->setText(QString(str + "/5"));
        wins++;
    }
    else
    {
        ui->textBrowser_2->clear();
        ui->textBrowser_2->append(tasks[page+1]);
        QString str = QString::number(count);
        ui->label->setText(QString(str + "/5"));
        fail++;
    }
    page++;
    qDebug() << page;
}

this is a slot called when the button is clicked. How can I make the page variable increase with each click?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Zhilin, 2016-06-19
@Anton3

At a minimum, you need to make page and count fields of the class.

J
Jacob E, 2016-06-20
@Zifix

Qt has absolutely nothing to do with it, you fundamentally do not understand what a scope is, there will be similar problems in any language.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question