Bug report #19184

QGis 3.0.3 crash using QSqlTableModel

Added by Alfredo GarciaWoods over 6 years ago. Updated over 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Python plugins
Affected QGIS version:3.0.3 Regression?:No
Operating System:Windows 10 Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:27013

Description

I am developing a Qgis plugin and Qgis 3.0.3 Crashes sometimes.
I know the source of the problem is QSqlTableModel, I am thinking that perhaps, is a matter of time… when I leave the plugin without any action for some minutes, perhaps the database connection is closed or something like that, and then, when I try to show the tableView again, it internally calls the broken connection(it is a presumption).

Stack Trace

QSqlQuery::value :
QSqlQueryModel::data :
QSqlTableModel::data :
QSortFilterProxyModel::lessThan :
QSortFilterProxyModel::qt_static_metacall :
QSortFilterProxyModel::sortRole :
QSortFilterProxyModel::sort :
QTableView::sortByColumn :
PyCFunction_FastCallDict :
PyObject_GenericGetAttr :
PyEval_EvalFrameDefault :
PyInit_pydevd_frame_evaluator_win32_36_64 :
PyObject_GenericGetAttr :
PyEval_EvalFrameDefault :
PyInit_pydevd_frame_evaluator_win32_36_64 :
PyFunction_FastCallDict :
PyObject_CallFunctionObjArgs :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QMetaObject::activate :
QAction::activate :
QAbstractButton::click :
QAbstractButton::mouseReleaseEvent :
QToolButton::mouseReleaseEvent :
QWidget::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :

QGIS Info
QGIS Version: 3.0.3-Girona
QGIS code revision: 8a899c8758
Compiled against Qt: 5.9.2
Running against Qt: 5.9.2
Compiled against GDAL: 2.2.4
Running against GDAL: 2.2.4

System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17134

History

#1 Updated by Alfredo GarciaWoods over 6 years ago

  • Status changed from Open to Closed

I finaly found that QGis crashed because I was using a:
QSqlDatabase->QSqlTableModel->QTableView schema

And the order to reinit this keeping the original QTableView, is very important.
The solution was to do it in order:
So that the model QTableView-> QSqlTableModel doesn’t try to access a populated model, and a closed databases

if self.db!=None:
self.model.revertAll()
self.model.clear()
self.db.close()

Also available in: Atom PDF