这是我在这个论坛上的第一篇帖子,我希望我所寻求的解决方案的问题已经被解释清楚了。我正在使用QSqlTableModel和QSqlTableView来查看数据库的一个表。缓存表模型正是我所寻找的,这就是为什么我选择了QSqlTableModel(还有其他模型吗?)。现在我需要将所有缓存的查询解析为xml,一旦我执行了submitAll() --我选择了OnManualSubmit作为编辑策略。我试图编写XML子类并重载insertRowInTable/updateRowInTable/deleteRowFromTable,,但是缓存被指向私有类的d指针访问,我找不到另一种方法来获取缓存的准备好的语句,然后将它们解析成QSqlTableModel。这是我认为不可能的解决方案吗?
我期待着任何回复。
发布于 2012-12-11 19:15:58
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(),以便在调用父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。
https://stackoverflow.com/questions/13699556
复制相似问题