- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我要为这个下层的每个结果计算新行
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/
我有一个我维护的数据库的小型管理应用程序。我所关注的表中的记录永远不会超过 1000 到 1500 条,而且只有大约八列数据。我查看它的表单是 QTableView 的子类,我正在使用 QSqlQue
我有一个包含查询结果的 QSqlQueryModel 可以有几万行。 这个模型有两个用例: 一个用例,我需要完整的模型来计算行的一些统计信息; 一个用例,我想显示内容的概览。 我的问题是第二种情况,什
我使用QSqlQueryModel查询一个postgresql数据库,我发现数据库中所有的Infinity和-Infinity值( double )我使用 model->data(index, Qt:
我正在尝试使用 QSqlQueryModel 来从我的数据库中检索一些值,例如: QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "test
我在实现 QSqlQueryModel 时无法理解如何访问返回的元素。 我知道你可以做到 QSqlQuery 查询; query.prepare("select * from database");
我希望通过 QSqlQueryModel 查询 SQL 数据库(PyqQt 5/Qt 5.2) 异步,因此 GUI 不会阻塞。如何实现?也许通过多线程?请提供如何执行此操作的代码。如果异步使用 QSq
我只想处理数据库并将结果添加到模型并将其发送到另一个类并在 GUI 中查看。摘要代码为: 我有一个公共(public)类成员: QSqlQueryModel *model; 加载数据并将其添加到模型
我要为这个下层的每个结果计算新行 QSqlQueryModel *model = new QSqlQueryModel(); model->setQuery("SELECT height,age fr
我很少有组合框,其中包含大约 10 万行或更多行的非常挖掘的数据集。我尝试使用 QStandardItemModel - 如果预加载模型,工作速度足够快,如果在单独的线程中执行,模型加载也需要几秒钟。
我有一个名为 Load 的类,它从数据库中加载数据。另一类是将数据显示在表格中。在我返回 QSqlQueryModel 的函数中,它是:目前只是基本的,因为我无法编译它: QSqlQueryModel
我有一个 lineExdit 和一个 tableView,我想根据在 lineEdit 中输入的文本实时更新 tableView。 void updateTableView(QString *st)
我在正确转置从 db 收到的表时遇到问题。我按照找到的路径 here ,并最终继承了 QAbstractProxyModel - 如描述的那样 here .不幸的是,它不能完全工作,这就是问题所在:
我想在 qml TableView 中显示 QSqlQueryModel,但我不想为每个新查询创建单独的 QML 文件,因为我无法创建给定的无限 qml 文件 here .还有 question对于动
为了加快 QComboBox 处理非常大的数据集,想尝试使用 QSqlQueryModel 而不是 QStandardItemModel。然而,QComboBox 中的文本数据我需要映射到一个 ID,
我在将 QSqlQueryModel 与准备好的语句一起使用时遇到问题。手动执行语句时一切正常,但将其绑定(bind)到模型时 - 它不会执行。另一方面,当我使用“静态”查询(通过 QString)设
我正在尝试从 QSqlQueryModel 中删除一行,如下所示: void MainWindow::deleteRecord() { int row_index= ui->tableView
我有一个显示QSqlQueryModel 的QTableView。该模型包含在第一列的每一行中创建的复选框(其中包含 ref_no;我的数据库中的主键)如下所示: void MainWindow::s
我想从我的 SQlite 数据库中获取模型,当我在 QSqlQueryModel 中设置查询时,我可以获得行数、列数等。但是每列中的数据我有一个 ReferenceError 试图获取列名cpp代码:
如果我们使用以下 QT 功能从 SQL 数据库获取数据 QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT na
我使用以下方法在 QTableView 中显示 select 语句的结果。我应该如何修改此代码以在同一 QTableView 中显示两个或多个不同选择语句的结果? QSqlDatabase db =
我是一名优秀的程序员,十分优秀!