gpt4 book ai didi

c++ - 将计算列添加到 Qt QSqlQueryModel

转载 作者:太空宇宙 更新时间:2023-11-04 13:35:47 24 4
gpt4 key购买 nike

我要为这个下层的每个结果计算新行

QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT height,age from patients", DB->getDB());
model->setHeaderData(4,Qt::Horizontal,tr("height"));
model->setHeaderData(2,Qt::Horizontal,tr("age"));
ui->tableView->setModel(model);
ui->tableView->show();

作为

ratio = height/age;

我可以吗?怎么办?

谢谢!

最佳答案

你可以的。

您可以访问 QSqlQueryModel 中的项目,例如:

QSqlRecord rec = model->record(row); // get the row you need
QVariant height = rec.field("height").value(); // or access it via index
QVariant age = rec.field("age").value();
double ratio = height.toDouble() / age.toDouble();

只需根据您的需要调整代码,并可能为其添加值检查。

干杯

关于c++ - 将计算列添加到 Qt QSqlQueryModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29644959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com