这是我在这个论坛的第一篇文章,我希望我要求解决的问题清楚地解释了。我正在使用QSqlTableModel和QSqlTableView来查看数据库的表。缓存的表模型是我正在寻找的,这就是我选择QSqlTableModel的原因(还有其他模型吗?)。现在我需要解析缓存的所有查询,一旦我执行submitAll() - 我选择了OnManualSubmit作为编辑策略。我试图编写QSqlTableModel的子类并重载insertRowInTable / updateRowInTable / deleteRowFromTable,但是通过指向私有类的d指针访问缓存,我找不到另一种方法来获取缓存的预准备语句,然后将它们解析为xml 。这个解决方案我认为不可能吗?
我期待着任何回复。
答案 0 :(得分:0)
QSqlTableModel继承了QSqlQueyModel,它有一个公共
QSqlQuery QSqlQueryModel::query () const
您可以连接到QSqlTableModel发出的四个更改信号
void beforeDelete ( int row )
void beforeInsert ( QSqlRecord & record )
void beforeUpdate ( int row, QSqlRecord & record )
void primeInsert ( int row, QSqlRecord & record )
(问题:我认为可以为同一事件发出primeInsert和BeforeInsert,不确定是否想到)
子类并重新实现submit()以在调用父提交之前发出包含QSqlQuery的信号:
bool YourChildModel::submit ()
{
emit yourSignal(query());
return QSqlTableModel::submit()
}
QsqlQuery有
QString QSqlQuery::lastQuery () const
Returns the text of the current query being used, or an empty string if there is no current query text.
QString QSqlQuery::executedQuery () const
Returns the last query that was successfully executed.
In most cases this function returns the same string as lastQuery(). If a prepared query with placeholders is executed on a DBMS that does not support it, the preparation of this query is emulated. The placeholders in the original query are replaced with their bound values to form a new query. This function returns the modified query. It is mostly useful for debugging purposes.
用于解析xml。