Qt5中void QSqlQuery::clear()和void QSqlQuery::finish()有什么区别?

What is the difference between void QSqlQuery::clear() and void QSqlQuery::finish() in Qt5?

文档在这个主题上有点含糊:

来自void QSqlQuery::clear()

Clears the result set and releases any resources held by the query. Sets the query state to inactive. You should rarely if ever need to call this function.

来自void QSqlQuery::finish()

Instruct the database driver that no more data will be fetched from this query until it is re-executed. There is normally no need to call this function, but it may be helpful in order to free resources such as locks or cursors if you intend to re-use the query at a later time.

Sets the query to inactive. Bound values retain their values.

一个暗示另一个吗?在每种情况下将释放哪些资源?为什么我要使用一个而不是另一个?

我觉得思路还是比较清晰的,功能之间并不互相暗含。第一个确实清除了所有内容:

Clears the result set and releases any resources held by the query

在那之后你将无法获得关于这个查询的任何信息,而第二个只是将查询标记为不活动(好吧,它只是 "says" 它是空的)并准备查询准备好成为

  1. 重新执行
  2. 清除

Bound values retain their values

表示finish().

执行后至少还有一些数据是可以访问的

如果您不想创建另一个 QSqlQuery 对象并希望执行完全不同的查询,那么您可以使用 clear() 而不必担心任何内存泄漏或其他问题。但是如果您计划稍后执行相同的查询,例如使用另一组绑定值,您可以使用 finish()。它还将释放一些驱动程序的内部资源(如文档中所述)。