Error : The inferior stopped because it received a signal from the operating system. Signal name : SIGABRT Signal meaning : Aborted
Unsolved
General and Desktop
-
Trying to build a very simple app that saves typed text into a database.
The app crashes after connecting to database with the popup (while debugging, the app doesnt give any reason debug information otherwise).
The inferior stopped because it received a signal from the operating system. Signal name : SIGABRT Signal meaning : Aborted
Trial3.h
#ifndef TRIAL03_H #define TRIAL03_H #include <QMainWindow> #include <QtSql> #include <QMessageBox> #include <iomanip> #include <iostream> QT_BEGIN_NAMESPACE namespace Ui { class Trial03; } QT_END_NAMESPACE class Trial03 : public QMainWindow { Q_OBJECT public: Trial03(QWidget *parent = nullptr); ~Trial03(); private slots: void submit1(); private: Ui::Trial03 *ui; QSqlDatabase dbCon; }; #endif // TRIAL03_H
Trial3.cpp
#include "trial03.h" #include "ui_trial03.h" Trial03::Trial03(QWidget *parent) : QMainWindow(parent) , ui(new Ui::Trial03) { ui->setupUi(this); dbCon = QSqlDatabase::addDatabase("QSQLITE"); dbCon.setDatabaseName("/T03.db"); try{ dbCon.open(); //QMessageBox::information(this, "Activated", "Connected"); throw(dbCon.lastError()); } catch(QString err){ QMessageBox::warning(this, "Error", err); qDebug() <<dbCon.lastError(); } } Trial03::~Trial03() { delete ui; } void Trial03::submit1() { try{ dbCon.open(); throw(dbCon.lastError()); } catch(QString err1){ QMessageBox::warning(this, "Error", err1); qDebug() <<dbCon.lastError(); } try{ QSqlDatabase::database().transaction(); QSqlQuery query(dbCon); query.prepare("INSERT INTO d1 (data) VALUES (:data)"); query.bindValue(":data",ui->submit1->text()); query.exec(); QSqlDatabase::database().commit(); throw(dbCon.lastError()); } catch(QString err2){ QMessageBox::warning(this, "Error", err2); qDebug() <<dbCon.lastError(); } dbCon.close(); }
have enabled
qt += sql
have tried using std::cout to get the runtime error via terminal, doesnt work.
-
Hi and welcome to devnet,
First thing: Qt does not use exceptions so you either need to adapt your code or follow the guide that shows how you may make use of them. My recommendation, drop the exception in that piece of code.
Next: why are you throwing everywhere in your code without doing a proper check of the return values of the method you use ?
Finally: don't store QDatabase objects, the class documentation explains why.