I do not know how you can more clearly describe this funny situation. For all the time I worked with Qt, I used the signals / slots mechanism. But what is happening now I can not describe. He spent a lot of time on solving this problem, but he never came to answer. So, there is a class that works with the database:
#ifndef DATABASE_H #define DATABASE_H #include <QObject> #include <QSql> #include <QSqlQuery> #include <QSqlError> #include <QSqlDatabase> #include <QFile> #include <QDate> #include <QDebug> class DataBase : public QObject { Q_OBJECT private: QSqlDatabase db; public: explicit DataBase(QObject *parent = 0); ~DataBase(){ db.close(); } signals: void updateLocationsModel(); public slots: /**...**/ void createLocalPoint(double lat, double lon, QString type); void deleteLocalPoint(int id); }; #endif // DATABASE_H A piece of his description:
void DataBase::createLocalPoint(double lat, double lon, QString type) { QSqlQuery query; query.prepare("INSERT INTO LocationsPoints (lat, lon, type) VALUES (:lat, :lon, :type);"); query.bindValue(":lat", lat); query.bindValue(":lon", lon); query.bindValue(":type", type); if (!query.exec()){ qDebug() << "Error SQLite:" << query.lastError().text(); } emit updateLocationsModel(); } void DataBase::deleteLocalPoint(int id) { QSqlQuery query; query.prepare("DELETE FROM LocationsPoints WHERE LocationsPoints.id = :id;"); query.bindValue(":id", id); if (!query.exec()){ qDebug() << "Error SQLite:" << query.lastError().text(); } qDebug() << query.lastQuery(); emit updateLocationsModel(); qDebug() << "++++++"; } Problem: When calling the createLocalPoint function, the code executes perfectly. Calling deleteLocalPoint crashes spontaneously. I did not see any sensible logic, but I tried to leave one line in this and that function
emit updateLocationsModel(); And you know what? Crash in the second function remained, and the first one worked and works ...
Not finding a solution, I went to the debug tab.
Here something clears up. Maybe QML is to blame for everything, which I also actively use.
A bit of the main.cpp file
LocationsModel locationsModel; QObject::connect(&db, SIGNAL(updateLocationsModel()), &locationsModel, SLOT(updateModel())); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QQmlContext* ctx = engine.rootContext(); ctx->setContextProperty("locationsModel", &locationsModel); In QML, functions are called like this:
dataBase.createLocalPoint(coordinates.latitude, coordinates.longitude, type); AND
dataBase.deleteLocalPoint(id); Here is the slot
void LocationsModel::updateModel() { QString str_query("SELECT "); str_query.append("LocationsPoints.id, "); str_query.append("LocationsPoints.lat, "); str_query.append("LocationsPoints.lon, "); str_query.append("LocationsPoints.type "); str_query.append("FROM LocationsPoints; "); this->setQuery(str_query); qDebug() << str_query << endl; qDebug() << "End" << endl; } For reference. It was established experimentally that both deleteLocalPoint is executed to the end and emit (Debug info is output to qDebug ())


valgrind. - αλεχολυτ