0

In one of my windows I made a button responsible for creating dynamic array of buttons. After they are made I can't make 'anul' button close the window Here's the code

QWidget *centralWidget = new QWidget;
        int licznik=1;
        QString licz;
        QString kolumny = ui->lineEdit->text();
        QString wiersze = ui->lineEdit_2->text();
        QPushButton *button[wiersze.toInt()][kolumny.toInt()];

        QGridLayout *controlsLayout = new QGridLayout;
        for(int i=0;i<wiersze.toInt();i++)
        {
            for(int j=0;j<kolumny.toInt();j++)
            {
                    licz = QString::number(licznik);
                    licznik++;
                    button[i][j] = new QPushButton(licz);
                    button[i][j]->setCheckable(1);
                    controlsLayout->addWidget(button[i][j], i, j);
            }
        }

        QPushButton *okej = new QPushButton("Zatwierdź");
        QPushButton *anul = new QPushButton("Anuluj");
        if(anul->isDown() == true)
            this->close();
        controlsLayout->addWidget(okej, wiersze.toInt(), 0);
        controlsLayout->addWidget(anul, wiersze.toInt(), 1);

        controlsLayout->setHorizontalSpacing(0);
        controlsLayout->setVerticalSpacing(0);
        centralWidget->setLayout(controlsLayout);

        setCentralWidget(centralWidget);

I also tried to change this->close() with centralWidget->close()

CentusDBWA
  • 11
  • 4

1 Answers1

0

This code is executed one time only.

 if(anul->isDown() == true)
            this->close();

What you want is to connect the clicked() signal of the button to a function (slot)

connect(anul, SIGNAL(clicked()), this,SLOT(close()))
Félix Cantournet
  • 1,941
  • 13
  • 17