diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index 03a705df..f24962d8 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -920,3 +920,18 @@ void SqliteTableModel::waitForFetchingFinished() if(m_futureFetch.isRunning()) m_futureFetch.waitForFinished(); } + +void SqliteTableModel::cancelQuery() +{ + if(m_rowCount.isRunning()) + { + m_rowCount.cancel(); + m_rowCount = QtConcurrent::run([=]() { + // Make sure we report 0 rows if anybody asks + return 0; + }); + } + + if(m_futureFetch.isRunning()) + m_futureFetch.cancel(); +} diff --git a/src/sqlitetablemodel.h b/src/sqlitetablemodel.h index 0f259f8a..ea957d70 100644 --- a/src/sqlitetablemodel.h +++ b/src/sqlitetablemodel.h @@ -75,6 +75,10 @@ public: public slots: void updateFilter(int column, const QString& value); + // This cancels the execution of the current query. It can't guarantee that the query is stopped immediately or after returning but it should + // stop soon afterwards. If some data has already been loaded into the model, that data is not deleted + void cancelQuery(); + signals: void finishedFetch();