Hi,
You could just define an array of pointers to QComboBox objects. If the column_number is a constant during compilation, you can use simple array definition. If the column_number is a variable, then you need to use new [] operator. Make sure though you are going to release memory by using delete []comboBox at the ned of application. Otherwise your memory will be slowly leaking.
// Data assigmnent window filling with input sub-widgets
QComboBox* comboBox
[column_number
];
// if column_number if a constant // QComboBox** comboBox = new QComboBox*[column_number]; // this will have to be release by using delete []comboBox;
for (unsigned int row = 0; row < columns_number; row++)
{
comboBox[row]->addItem(tr("To be set..."));
comboBox[row]->addItem(tr("A"));
comboBox[row]->addItem(tr("B"));
comboBox[row]->addItem(tr("C"));
comboBox[row]->addItem(tr("D"));
grid->addWidget(Label, row, 0);
grid->addWidget(comboBox[row], row, 1);
}
//
data_assigment_input->setLayout(grid);
// Quit push button creation
// quit->setFont(QFont("Times", 18, QFont::Bold));
// Connection between widgets
connect(quit, SIGNAL(clicked()), window_data_assignment, SLOT(close()));
// Size/Position auto-managment by QVBoxLayout
wlayout->addWidget(data_assigment_input);
wlayout->addWidget(quit);
window_data_assignment->setLayout(wlayout);
// Data assigmnent window filling with input sub-widgets
QComboBox* comboBox[column_number]; // if column_number if a constant
// QComboBox** comboBox = new QComboBox*[column_number]; // this will have to be release by using delete []comboBox;
for (unsigned int row = 0; row < columns_number; row++)
{
Label = new QLabel(tr("Data ")+QString::number(row+1)+" :");
comboBox[row]->addItem(tr("To be set..."));
comboBox[row]->addItem(tr("A"));
comboBox[row]->addItem(tr("B"));
comboBox[row]->addItem(tr("C"));
comboBox[row]->addItem(tr("D"));
grid->addWidget(Label, row, 0);
grid->addWidget(comboBox[row], row, 1);
}
//
data_assigment_input->setLayout(grid);
// Quit push button creation
QPushButton *quit = new QPushButton(tr("OK"));
// quit->setFont(QFont("Times", 18, QFont::Bold));
// Connection between widgets
connect(quit, SIGNAL(clicked()), window_data_assignment, SLOT(close()));
// Size/Position auto-managment by QVBoxLayout
QVBoxLayout *wlayout = new QVBoxLayout;
wlayout->addWidget(data_assigment_input);
wlayout->addWidget(quit);
window_data_assignment->setLayout(wlayout);
To copy to clipboard, switch view to plain text mode
A side note, I usually use size_t, which is probably an equivalent of uint, as a counter. Also, when you define a variable, try to get used to start variable names with lower case letters, like thisFormOfName. Names beginning with a capital letter should be reserved for new classes, e.g. myNewObject of MyNewClass MyWindow, MyLabel etc. Also, the variable counter_number has different form of name: my_new_varialbe. It is also a good habit to stick to one form, either new_name or newName. It is easier to analyse a code. I also add suffix describing what variable represents QLabel, QPushButton etc. For instance, quitButton, vegComboBox, firstLabel, secondLabel, firstEdit, secondEdit (QEditLine). This helps to write code when Qt suggest names.
Bookmarks