我是一名学生程序员,并且一直在为我的公司构建 Qt 中的 GUI。我正在编写一个成员函数 SetData 基本上充当我的 Ui 元素和成员变量之间的中介。在这个特定的 UI 中,我使用的是 QTableWidge。我似乎无法确切知道如何将每列设置为变量。
例如,如果我的 QTableWidget 中有 Name 列,并且 Name 是第一列,我无法使用传统的数组参数访问它。Qt的文档对于如何解决这个问题真的很模糊。也可能是我仍然太业余,无法理解如何使用类的成员函数来实现我想要的结果。
为了澄清我正在尝试为整个列定义数据类型。例如我的第一列;名称,将是我创建的一个变量,它是一个 QString 数据类型。SetData 最终会将其传递给 QVector 或 QList。这是我到目前为止输入的代码,有点想知道我认为我可以做什么。
void InjectionDialog::setData(InjectionData &setDataStruct)
{
/*The following setData functions assists in creating a new instance of
the Injection dialog with whatever values are passed to setDataStruct*/
QString str;//created str to make datatype conversion
ui->lineEditFluidVelocity->setText(str.setNum(setDataStruct.lineEditFluidVelocity));
ui->lineEditFluidMassFlow->setText(str.setNum(setDataStruct.lineEditFluidMassFlow));
ui->lineEditFluidArea->setText(str.setNum(setDataStruct.lineEditFluidArea));
ui->lineEditFluidTemperature->setText(str.setNum(setDataStruct.lineEditFluidTemperture));
ui->lineEditFluidPressure->setText(str.setNum(setDataStruct.lineEditPressure));
ui->lineEditParticleManual->setText(str.setNum(setDataStruct.lineEditManualParticlesPerCell));
ui->lineEditParticleVelocity->setText(str.setNum(setDataStruct.lineEditParitcleVelocity));
ui->lineEditParticleMassFlow->setText(str.setNum(setDataStruct.lineEditParticleMassFlow));
ui->lineEditParticleArea->setText(str.setNum(setDataStruct.lineEditParticleArea));
ui->lineEditParticleTemperature->setText(str.setNum(setDataStruct.lineEditParticleTemperture));
ui->tableWidgetInjectionLocations //this is where I got stuck
}
我知道 QTreeView 可以选择通过委派列来设置项目,但我需要能够编辑这些字段。在处理我的 QTableWidget 时,我可能会出错;如果是这样,我很感激有关如何正确处理此小部件的任何建议。