I'm a beginner in C++. I was making a test application in Qt and came across this problem: Where do I have to declare a variable in order to use it in a function like on_pushButton_clicked() ?
I tried making a main function and declaring the variable there and always got this error when changing the variable in another function: error: reference to non-static member function must be called; did you mean to call it with no arguments? Then I tried declaring the variable directly (not in any function) but that didn't work either.
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}
int main() {
    int x = 0;
    return 0;
}
MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::on_pushButton_clicked()
{
    x++; //here's the error
    ui->label->setText("number is:");
}
Is there a way to declare that variable (x) so that I can access it through on_pushButton_clicked()?
 
    