QSqlQuery throwing a SIGABRT on .clear() or cleanup
-
My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.
int cycleCount = 0; int zoneid; QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere query.exec("SELECT MAX(zoneid) FROM zone_settings"); query.next(); int maxCount = query.value(0).toInt(); zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere //query.clear() //Does not crash query.exec("SELECT zoneid FROM zone_settings"); //while (query.next()) //{ // cycleCount++; // zoneid = query.value(0).toInt(); // zoneList[zoneid].id = zoneid; //} //query.clear(); //Crashes int returnedValues = query.size(); for (int i = 0; i < returnedValues - 1; i++){ query.next(); cycleCount++; zoneid = query.value(0).toInt(); zoneList[zoneid].id = zoneid; } query.clear(); //Does not crash -
My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.
int cycleCount = 0; int zoneid; QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere query.exec("SELECT MAX(zoneid) FROM zone_settings"); query.next(); int maxCount = query.value(0).toInt(); zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere //query.clear() //Does not crash query.exec("SELECT zoneid FROM zone_settings"); //while (query.next()) //{ // cycleCount++; // zoneid = query.value(0).toInt(); // zoneList[zoneid].id = zoneid; //} //query.clear(); //Crashes int returnedValues = query.size(); for (int i = 0; i < returnedValues - 1; i++){ query.next(); cycleCount++; zoneid = query.value(0).toInt(); zoneList[zoneid].id = zoneid; } query.clear(); //Does not crash@Xenthan said in QSqlQuery throwing a SIGABRT on .clear() or cleanup:
zoneList[zoneid].id
Check for zoneid out of bounds or better use an appropriate container instead c magic.
-
My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.
int cycleCount = 0; int zoneid; QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere query.exec("SELECT MAX(zoneid) FROM zone_settings"); query.next(); int maxCount = query.value(0).toInt(); zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere //query.clear() //Does not crash query.exec("SELECT zoneid FROM zone_settings"); //while (query.next()) //{ // cycleCount++; // zoneid = query.value(0).toInt(); // zoneList[zoneid].id = zoneid; //} //query.clear(); //Crashes int returnedValues = query.size(); for (int i = 0; i < returnedValues - 1; i++){ query.next(); cycleCount++; zoneid = query.value(0).toInt(); zoneList[zoneid].id = zoneid; } query.clear(); //Does not crash -
My program is crashing when a QSqlQuery object is either being cleared or deleted, but only if the query is on an invalid entry. So if I call "while (query.next())" it will crash, but if I stop it at the second to last entry then it will delete just fine. It's returning valid values from the database, so I know the database is opening properly and that QSqlQuery is reading properly.
int cycleCount = 0; int zoneid; QSqlQuery query(sql); //sql is a QSqlDatabase declared elsewhere query.exec("SELECT MAX(zoneid) FROM zone_settings"); query.next(); int maxCount = query.value(0).toInt(); zoneList = new zoneInfo[maxCount]; //Custom struct pointer declared elsewhere //query.clear() //Does not crash query.exec("SELECT zoneid FROM zone_settings"); //while (query.next()) //{ // cycleCount++; // zoneid = query.value(0).toInt(); // zoneList[zoneid].id = zoneid; //} //query.clear(); //Crashes int returnedValues = query.size(); for (int i = 0; i < returnedValues - 1; i++){ query.next(); cycleCount++; zoneid = query.value(0).toInt(); zoneList[zoneid].id = zoneid; } query.clear(); //Does not crash@Xenthan said in QSqlQuery throwing a SIGABRT on .clear() or cleanup:
zoneList[zoneid].id
Check for zoneid out of bounds or better use an appropriate container instead c magic.
-
@Xenthan
https://doc.qt.io/qt-6/qsqlquery.html#clear hardly encourages you to use it! You use the sameQSqlQuery queryinstance for two distinctexec()statements. If you use two separate instances do you have any crash?This was it, at some point the database data became zero referenced so I was 1 element short on the array.
-
X Xenthan has marked this topic as solved on
-
X Xenthan has marked this topic as unsolved on
-
X Xenthan has marked this topic as solved on