如何在Qtableview中获取所选组合框的行值
How to get rowvalue of selected combobox in Qtableview?
我有Qtableviews,我在table2中添加了combobox,combobox中的值从table1 col0中获取,所以当用户在combo2中选择项目时,我需要获取所选项目的行值?
-
如何使用indexwidget?
-
在得到行值之后,我可以比较组合框文本并执行计算。由于我共享的是有效的,但当用户在2行(diff(组合框中选择相同的值时,它就不起作用了(2次内无法获取数据(。
void Gear_model::calR2() {
QAbstractItemModel* table1 = ui.tableView->model();
QAbstractItemModel* table2 = ui.tableView_2->model();
QComboBox* combo2;
QString col2;
for (int irowsl = 0, maxI = table2->rowCount(); irowsl < maxI; ++irowsl)
{
const QModelIndex idx1 = table2->index(irowsl, 2);
combo2 = qobject_cast<QComboBox*>(ui.tableView_2->indexWidget(idx1));
col2 = combo2->currentText();
for (int irowsM = 0, maxI = table2->rowCount(); irowsM < maxI; ++irowsM) {
qDebug() << "combo2 =" << col2;
if (col2 == table1->data(table1->index(irowsM, 0)).toString()) {
double pitchradius2 = table1->data(table1->index(irowsM, 6)).toDouble();
table2->setData(table2->index(irowsl, 10), radius2);
qDebug() << "R2 =" << col2 << radius2;
}
}
}
无法弄清楚如何为每一行获取组合框的选定值?
我找到了解决方案燃烧后2我添加了
if (combo2!=NULL) {
//my previous code
}
相关文章:
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 可组合的lambda/std::函数与std::可选
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- QTableView:endMoveRows在模型中重置水平页眉大小
- 混合组合和继承的C++问题
- 我需要将多个函数组合为一个函数
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 将QIcon添加到QTableView单元格
- 通过组合不同的类型来创建唯一的id
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 模板元编程:如何将参数包组合成新的参数包
- 检查向量是否具有所有可能的字符组合
- 如何在加密++中将两个源组合成新的源
- 根中的组合
- 如何在QTableView中排序和更改日期格式
- 更改 C++ 中的组合分类变量
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- 组合字符串不适用于 libCurl,C++
- QTableview Search
- 使用列中的组合框编辑QTableView