I have an n and m as two global variables and I wish to generate a grid of buttons size n*m. I have a combo box which changes n and m if the option is changed. My question is how do I update the grid?

Here is my code:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QPushButton"
#include "QGridLayout"
#include "QLabel"
#include "QComboBox"
#include "QDebug"

int n=9,m=9;

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QWidget *centralWidget = new QWidget;
int count=1,i,j;

QPushButton *button[10][10];
QGridLayout *controlsLayout = new QGridLayout;
QGridLayout *controlsLayout1 = new QGridLayout;
QPushButton *Reset=new QPushButton;
QLabel *Bombs=new QLabel;
QLabel *Timer=new QLabel;

Timer->setText("timer");
Bombs->setText("bombs");

QStringList commands = { "Easy", "Medium", "Hard", "Custom" };
QComboBox* combo = new QComboBox(this);
combo->addItems(commands);
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(commandChanged(int)));

controlsLayout->addWidget(combo,0,0,1,2);
controlsLayout->addWidget(Bombs,1,0);
controlsLayout->addWidget(Reset,1,4);
controlsLayout->addWidget(Timer,1,8);

Reset->setMinimumSize(40,40);
Reset->setMaximumSize(40,40);

for(i=2;i<n;i++)
{
for(j=0;j<m;j++)
{
if(count<=100)
{

button[i][j] = new QPushButton();
button[i][j]->setMinimumSize(40,40);
button[i][j]->setMaximumSize(40,40);
button[i][j]->move(40*j, 40*i);
button[i][j]->show();
controlsLayout->addWidget(button[i][j], i, j);
count++;
}
}
}
controlsLayout->setSpacing(5);
centralWidget->setLayout(controlsLayout);
setCentralWidget(centralWidget);
}
void MainWindow::commandChanged(int index)
{
if (index==0){n=9;m=9;}
else{n=9;m=9;}

qDebug() << n<<" "<<m;

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