如何将动态多维 QComboBox 插入 LayOut

How to insert a dynamic multidimensional QComboBox into a LayOut

我正在尝试从动态多维 QComboBox 中插入多个 QComboBox,例如:

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

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

但这给了我一个错误:从 QComboBox 到 *QWidget 的转换不可行。

使用:

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

工作正常。

我的情况是(这是示例):

  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

  }

我的案例所做的是基于我加载的文件,找到我将拥有的表的数量以及需要在其中输入的值的数量。这就是为什么我需要一个动态的多维 QComboBox。

我不正确的语法(或执行顺序)是什么? 如果这是重复的,那么我提前抱歉,但我找不到它,问题已经发布在这里。

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

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

}

其中 fieldAmount 是

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