Home > Net >  How to insert a dynamic multidimensional QComboBox into a LayOut
How to insert a dynamic multidimensional QComboBox into a LayOut

Time:01-01

I'm trying to insert multiple QComboBoxes from a dynamic multidimensional QComboBox like :

QComboBox **test = new QComboBox *[x];
test[x] = new QComboBox [y];

ui->QVBoxLayout->addWidget(test["one of x values"]["one of y values"]);

But this gives me an error of : no viable convert from QComboBox to *QWidget.

Using :

  QComboBox *test = new QComboBox;
  ui->QVBoxLayout->addWidget(test);

Works just fine.

My case is (this is examplery):

  for(int tmp = 1; fieldAmount >= tmp; tmp  ){
            //fieldAmount is the number of fields presented in a table that was loaded in from a file
            combobox1[currentTable] = new QComboBox [tmp];
            ui->verticalLayout_2->addWidget(&combobox1[currentTable][tmp]); //Gives the seg fault

  }

What my case does is based on a file that I load in, finds the amount of tables i will have and in them the amount of values that needs to be entered. That is why I need a dynamic multidimensional QComboBox.

What is the syntax (or execution order) that I'm not getting right ? If this is a duplicate, than im sorry in advance but I was not able to find it the question already posted on here.

CodePudding user response:

combobox1[currentTable] = new QComboBox [fieldAmount];
for(int tmp = 0; fieldAmount > tmp; tmp  ){

ui->verticalLayout_2->addWidget(&combobox1[currentTable][tmp]);

}

where fieldAmount is

int fieldAmount = (SQLDataBaseContet->record()).count()-1; // -1 as offset because of id
  • Related