Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by retinotop for How do I display a counter function in qt

#include "form.h"
#include "ui_form.h"
#include <QString>
#include <QLabel>

Form::Form(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form)
{
    counter = 0;
    ui->setupUi(this);
}

Form::~Form()
{
    delete ui;
}

void Form::on_pushButton_clicked()
{
    counter++;
    ui->label->setText(QString::number(counter));
}

Initialize your member in the constructor not in the header. And put the definition of your counter member to the private section not to the private slot section.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>