[Solved] The "best" way to programmatically refresh a QSqlQueryModel when the content of the query changes
-
QSqlTableModel::select() use setQuery( QString, QSqlDatabase ) method refresh contents. I guess you could do it the same way.
-
Hi all
I have similar question I am use QTableView + QSqlQuery when I set query at first time I allow fetch only first 10 rows from query, after that according user decides I can fetch next few rows, but my QTableView is not refreshed after fetch. I can't use setQuery because I do not what run sql yet one time to get result that I already have.
I try to use something like this
@emit dataChanged(createIndex(OldRowCnt, 1), createIndex(RowCount, HeaderCount));@
but this has no resultthank you for future help )
-
beginInsertRows solve my problem, I am call it after fetch
@bool cOciQModel::fetch(int Cnt, bool SilentMode) {
if (RowCount && !query->seek(RowCount - 1)) {
LastError = QString("Can't goto [%1] position").arg(QString::number(RowCount - 1));
return false;
}
int OldRowCnt = RowCount;
int Count = Cnt + 1;
while (--Count && !AllDataFetched) {
AllDataFetched = !query->next();
if (!AllDataFetched) {
++RowCount;
}
}if (!SilentMode) {
beginInsertRows(QModelIndex(), OldRowCnt, RowCount);
endInsertRows();
}return true;
}@
-
@iamantony how to do it with Python?
-
@Gelo Replace -> with .
-
@Gelo Yes, it is C++.
QString is a Qt data type for strings - no need to write it in Python.