定义函数:
传两个参数,一个引用,一个返回
public:ThpRecord getLatestRecord(QVector<int>& ids);
};ThpRecord faceinit::getLatestRecord(QVector<int>& ids) {ThpRecord entity;// 创建一个 SQL 查询对象QSqlQuery query;// 执行查询,假设表名为 "thp_record"query.exec("SELECT userId, updated_at FROM thp_record ORDER BY updated_at DESC LIMIT 1");if (query.next()) {entity.userId = query.value(0).toInt();entity.updatedAt = query.value(1).toString();// 将查询到的 userId 添加到 ids 向量中ids.append(entity.userId);} else {qDebug() << "No record found or query failed:" << query.lastError().text();}return entity;
}
调用:
faceinit fi;QVector<int> ids;ThpRecord latestRecord = fi.getLatestRecord(ids);if (latestRecord.userId != -1) {qDebug() << "Latest record - UserID:" << latestRecord.userId<< "Updated at:" << latestRecord.updatedAt;qDebug() << "IDs vector:" << ids;} else {qDebug() << "No record found.";}