QTableView 获取具有相似列 values/Data 的行列表

QTableView get list of rows with similar column values/Data

我有 QTableView with data generated from .csv file. The QTableView has column called Date (QDateTime) that covers over a month. I want to select a date and split the data for that date from the QTableView,所以我可以总结并平均其他列中的值。

类似于 SQL Table 查询,或类似于此 C# LINQ 语法:

var result = context.data.Where(n => n.date == date);

您可以遍历 table 查看数据并提取所需信息。作为演示,请查看给定的示例:

void findDates(QTableView *table, const QDateTime &date)
{
  auto model = table->model();
  const int dateColumn = 1; // The column with the dates data

  for (int row = 0; row < model->rowCount(); ++row)
  {
    auto idx = model->index(row, dateColumn);
    auto data = idx.data();
    auto d = data.toDateTime();

    // Comparison of dates
    if (d > date)
    {
      // Do something
    }
    else
    {
      // Do something else
    }
  }
}