我只是想将小部件添加到我的表小部件中,我正在尝试下面的代码,但是我一直运行程序,第一个小部件被添加但其余部分没有添加。你能帮我解决这个问题吗?
if(req.at(index).request.CodedValue.size() > 1 )
{
int rowNumber = -1;
for ( int paramNumber = 0 ; paramNumber < req.at(index).request.params.size(); paramNumber++)
{
if(req[index].request.params[paramNumber].semantic == "DATA")
{
rowNumber++;
QComboBox* reqComboBox = new QComboBox();
QLineEdit* tableReqLineEdit = new QLineEdit();
for ( int codedCounter = 0; codedCounter < req.at(index).request.CodedValue.at(paramNumber).trams.size(); codedCounter++)
{
// you should look for the subfunctions and add according to them
reqComboBox->addItem((req[index].request.CodedValue[paramNumber].trams[codedCounter].valueName));
QObject::connect(reqComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_tableCombobox_currentIndex());
}
ui.tableWidget->setCellWidget(rowNumber,1,reqComboBox);
}
}
}
答案 0 :(得分:1)
使用qDebug
查看for循环的执行次数。可能它只执行一次:
#include <QDebug>
...
rowNumber++;
qDebug() << rowNumber;
...
尝试以下方法:
for (int i=0; i<ui.tableWidget->rowCount(); i++)
{
ui.tableWidget->setCellWidget(i,1,new QLineEdit);
}
您看到多少行编辑?
请注意,您应该使用setRowCount
来设置表格小部件的行数。