Qt crash on Mac because of db
-
wrote on 16 Apr 2023, 12:10 last edited by
Hello, I am creating simple Qt project with database, I have used QSql but when I tried to get data from db, my app crashes and gives "Problem report, QtApp quit unexpectedly". And I thought it was from Sql but I used just txt, bin and dat binary files in c++ and nothing changed, I have changed settings and give access Qt creator and my app to all hard disk folders, but nothing changed. What is problem?
My computer runs on macOS 13, M1 Pro chip
#crash, #macOS, #mac -
Hello, I am creating simple Qt project with database, I have used QSql but when I tried to get data from db, my app crashes and gives "Problem report, QtApp quit unexpectedly". And I thought it was from Sql but I used just txt, bin and dat binary files in c++ and nothing changed, I have changed settings and give access Qt creator and my app to all hard disk folders, but nothing changed. What is problem?
My computer runs on macOS 13, M1 Pro chip
#crash, #macOS, #mac@madaminov0888 said in Qt crash on Mac because of db:
What is problem?
re-read your question and ask yourself how we should help with such a description.
Please provide some code and/or use a debugger to see why it crashes.
-
Hello, I am creating simple Qt project with database, I have used QSql but when I tried to get data from db, my app crashes and gives "Problem report, QtApp quit unexpectedly". And I thought it was from Sql but I used just txt, bin and dat binary files in c++ and nothing changed, I have changed settings and give access Qt creator and my app to all hard disk folders, but nothing changed. What is problem?
My computer runs on macOS 13, M1 Pro chip
#crash, #macOS, #macwrote on 16 Apr 2023, 12:15 last edited by@madaminov0888 said in Qt crash on Mac because of db:
And I thought it was from Sql but I used just txt, bin and dat binary files in c++ and nothing changed
Then create a minimal, 4-line Qt program without any database and see if that crashes.
-
@madaminov0888 said in Qt crash on Mac because of db:
What is problem?
re-read your question and ask yourself how we should help with such a description.
Please provide some code and/or use a debugger to see why it crashes.
wrote on 16 Apr 2023, 12:27 last edited by@Christian-Ehrlicher that is the problem I don't know either, why is crashing in the terminal print only "QtApp crashed", when I tried to read data from db, it is simple phone book app that get data from user and saves in db,
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QListWidgetItem>
#include <QString>
#include "myitem.h"
#include <fstream>
#include "user.h"
#include <iostream>using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{User u; fstream file; string filename = "/Users/muhammadjonmadaminov/Desktop/QtProjects/Calculator/data.bin"; file.open(filename, ios::binary | ios::in | ios::out | ios::app); if (!file.is_open()) { // if the file does not exist, create it file.open(filename, ios::binary | ios::out); if (!file.is_open()) { cout << "Error creating file" << endl; } file.close(); // try to open the file again in append mode file.open(filename, ios::binary | ios::in | ios::out | ios::app); if (!file.is_open()) { cout << "Error opening file" << endl; } } ui->setupUi(this); ui->tabWidget->tabBar()->hide(); ui->tabWidget->setCurrentWidget(ui->tab); file.seekg(0); while(file.read((char*)&u,sizeof(u))){ QString name = u.getName(); //QString surname = u.getSurname(); QString number = u.getNumber(); QListWidgetItem *item = new QListWidgetItem; MyItem *myitem = new MyItem(name, number); ui->listWidget->addItem(item); item->setSizeHint(QSize(0, 70)); ui->listWidget->setItemWidget(item, myitem); } file.close();
}
this is the code. -
@madaminov0888 said in Qt crash on Mac because of db:
And I thought it was from Sql but I used just txt, bin and dat binary files in c++ and nothing changed
Then create a minimal, 4-line Qt program without any database and see if that crashes.
wrote on 16 Apr 2023, 12:39 last edited by@JonB no it would not crash because the reason of crash is opening file or Sql db, there is not error while debugging and running application, crash occurs when I run code and app opens and when I input data and push button save or get from db, app just quits. My description can't give more info about crash but I don't know either why is this happening.
-
@JonB no it would not crash because the reason of crash is opening file or Sql db, there is not error while debugging and running application, crash occurs when I run code and app opens and when I input data and push button save or get from db, app just quits. My description can't give more info about crash but I don't know either why is this happening.
Apart from the fact that I don't see any sql code or database here - use a debugger and see where it crashes. That's the live of a developer.
-
Apart from the fact that I don't see any sql code or database here - use a debugger and see where it crashes. That's the live of a developer.
wrote on 16 Apr 2023, 13:30 last edited by@Christian-Ehrlic I said I used Sql and it crashed because of that I tried using binary files and even just .txt files, and nothing changed, I don't think it is from Qt or debug, I think there is some error with macOS 13, in previous 12 or 11 versions it worked I reported in macOS care, and waiting for answer, I did not find anything but thank you for your answers
-
@Christian-Ehrlic I said I used Sql and it crashed because of that I tried using binary files and even just .txt files, and nothing changed, I don't think it is from Qt or debug, I think there is some error with macOS 13, in previous 12 or 11 versions it worked I reported in macOS care, and waiting for answer, I did not find anything but thank you for your answers
@madaminov0888 said in Qt crash on Mac because of db:
, and waiting for answer,
Just a reminder: A program you created is crashing on your computer and you are waiting that it goes away magically?
I don't see how we can help here - esp. since you want something from us but don't provide anything except some code pieces which don't compile/aren't complete and no hint where it crashes.
-
@madaminov0888 said in Qt crash on Mac because of db:
, and waiting for answer,
Just a reminder: A program you created is crashing on your computer and you are waiting that it goes away magically?
I don't see how we can help here - esp. since you want something from us but don't provide anything except some code pieces which don't compile/aren't complete and no hint where it crashes.
wrote on 16 Apr 2023, 14:12 last edited by@Christian-Ehrlicher ok ok, there was my mistake in settings accesebilty wasn't changed to application it was changed to Qt creator and because of that my Mac did not give me access to use file or db. And after that App did not Quit quickly, I debugged and get this error:
Calculator(7947,0x1f954db40) malloc: *** error for object 0x600003ee81e0: pointer being freed was not allocated Calculator(7947,0x1f954db40) malloc: *** set a breakpoint in malloc_error_break to debug Detected Qt Version: 0x60500 (namespace='no namespace') Found function QObject::property: 0x101db2b24 Found function QObject::customEvent: 0x101daaaf4
this was my code:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QListWidgetItem> #include <QString> #include "myitem.h" #include <fstream> #include "user.h" #include <iostream> #include <QSqlError> #include <iostream> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { User u; fstream file; //string filename = "/Users/muhammadjonmadaminov/Desktop/QtProjects/Calculator/date.txt"; db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("./data.db"); if(db.open()){ cout << "Data opened " << endl; } else{ qDebug() << db.lastError().databaseText(); } query = new QSqlQuery(db); query->prepare("insert into TelephoneBook (Name, Surname, Number)"); //query->exec("CREATE TelephoneBook(Name TEXT, Surname text, Number TEXT);"); ui->setupUi(this); ui->tabWidget->tabBar()->hide(); ui->tabWidget->setCurrentWidget(ui->tab); file.seekg(0); while(file.read((char*)&u,sizeof(u))){ QString name = u.getName(); //QString surname = u.getSurname(); QString number = u.getNumber(); QListWidgetItem *item = new QListWidgetItem; MyItem *myitem = new MyItem(name, number); ui->listWidget->addItem(item); item->setSizeHint(QSize(0, 70)); ui->listWidget->setItemWidget(item, myitem); } file.close(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { ui->lineEdit_4->clear(); ui->lineEdit_5->clear(); ui->lineEdit_6->clear(); ui->tabWidget->setCurrentWidget(ui->tab_2); } void MainWindow::on_listWidget_itemDoubleClicked(QListWidgetItem *item) { ui->tabWidget->setCurrentWidget(ui->tab); fstream file; User u; QString tx; QString number; QString surname; string filename = "/Users/muhammadjonmadaminov/Desktop/QtProjects/Calculator/date.txt"; file.open(filename, ios::binary | ios::in | ios::out | ios::app); if (!file.is_open()) { // if the file does not exist, create it file.open(filename, ios::binary | ios::out); if (!file.is_open()) { cout << "Error creating file" << endl; } file.close(); // try to open the file again in append mode file.open(filename, ios::binary | ios::in | ios::out | ios::app); if (!file.is_open()) { cout << "Error opening file" << endl; } } if (dynamic_cast<MyItem*>(ui->listWidget->itemWidget(item))) { tx = dynamic_cast<MyItem*>(ui->listWidget->itemWidget(item))->text(); number = dynamic_cast<MyItem*>(ui->listWidget->itemWidget(item))->text_2(); } else { tx = item->text(); } file.seekg(0); while(file.read((char*)&u, sizeof(u))){ if(u.getName() == tx and u.getNumber() == number){ surname = u.getSurname(); } } ui->lineEdit->setText(tx); ui->lineEdit_2->setText(surname); ui->lineEdit_3->setText(number); } void MainWindow::on_pushButton_2_clicked() { db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("./data.db"); if(db.open()){ cout << "Data opened " << endl; } else{ qDebug() << db.lastError().databaseText(); } query = new QSqlQuery(db); User u; QListWidgetItem * item =new QListWidgetItem; QString name = ui->lineEdit_4->text(); QString surname = ui->lineEdit_5->text(); QString number = ui->lineEdit_6->text(); u.setData(name, surname, number); query->prepare("insert into TelephoneBook(Name, Surname,Number) values ('" + name + "', '" + surname + "', '" + number + "')"); if(query->exec()){ cout << "All done" << endl; db.close(); } MyItem *myitem = new MyItem(name, number); ui->listWidget->addItem(item); item->setSizeHint(QSize(0,70)); ui->listWidget->setItemWidget(item, myitem); ui->tabWidget->setCurrentWidget(ui->tab); }
and in terminal returned this error:
Data opened QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed. Data opened
-
@Christian-Ehrlicher ok ok, there was my mistake in settings accesebilty wasn't changed to application it was changed to Qt creator and because of that my Mac did not give me access to use file or db. And after that App did not Quit quickly, I debugged and get this error:
Calculator(7947,0x1f954db40) malloc: *** error for object 0x600003ee81e0: pointer being freed was not allocated Calculator(7947,0x1f954db40) malloc: *** set a breakpoint in malloc_error_break to debug Detected Qt Version: 0x60500 (namespace='no namespace') Found function QObject::property: 0x101db2b24 Found function QObject::customEvent: 0x101daaaf4
this was my code:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QListWidgetItem> #include <QString> #include "myitem.h" #include <fstream> #include "user.h" #include <iostream> #include <QSqlError> #include <iostream> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { User u; fstream file; //string filename = "/Users/muhammadjonmadaminov/Desktop/QtProjects/Calculator/date.txt"; db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("./data.db"); if(db.open()){ cout << "Data opened " << endl; } else{ qDebug() << db.lastError().databaseText(); } query = new QSqlQuery(db); query->prepare("insert into TelephoneBook (Name, Surname, Number)"); //query->exec("CREATE TelephoneBook(Name TEXT, Surname text, Number TEXT);"); ui->setupUi(this); ui->tabWidget->tabBar()->hide(); ui->tabWidget->setCurrentWidget(ui->tab); file.seekg(0); while(file.read((char*)&u,sizeof(u))){ QString name = u.getName(); //QString surname = u.getSurname(); QString number = u.getNumber(); QListWidgetItem *item = new QListWidgetItem; MyItem *myitem = new MyItem(name, number); ui->listWidget->addItem(item); item->setSizeHint(QSize(0, 70)); ui->listWidget->setItemWidget(item, myitem); } file.close(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { ui->lineEdit_4->clear(); ui->lineEdit_5->clear(); ui->lineEdit_6->clear(); ui->tabWidget->setCurrentWidget(ui->tab_2); } void MainWindow::on_listWidget_itemDoubleClicked(QListWidgetItem *item) { ui->tabWidget->setCurrentWidget(ui->tab); fstream file; User u; QString tx; QString number; QString surname; string filename = "/Users/muhammadjonmadaminov/Desktop/QtProjects/Calculator/date.txt"; file.open(filename, ios::binary | ios::in | ios::out | ios::app); if (!file.is_open()) { // if the file does not exist, create it file.open(filename, ios::binary | ios::out); if (!file.is_open()) { cout << "Error creating file" << endl; } file.close(); // try to open the file again in append mode file.open(filename, ios::binary | ios::in | ios::out | ios::app); if (!file.is_open()) { cout << "Error opening file" << endl; } } if (dynamic_cast<MyItem*>(ui->listWidget->itemWidget(item))) { tx = dynamic_cast<MyItem*>(ui->listWidget->itemWidget(item))->text(); number = dynamic_cast<MyItem*>(ui->listWidget->itemWidget(item))->text_2(); } else { tx = item->text(); } file.seekg(0); while(file.read((char*)&u, sizeof(u))){ if(u.getName() == tx and u.getNumber() == number){ surname = u.getSurname(); } } ui->lineEdit->setText(tx); ui->lineEdit_2->setText(surname); ui->lineEdit_3->setText(number); } void MainWindow::on_pushButton_2_clicked() { db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("./data.db"); if(db.open()){ cout << "Data opened " << endl; } else{ qDebug() << db.lastError().databaseText(); } query = new QSqlQuery(db); User u; QListWidgetItem * item =new QListWidgetItem; QString name = ui->lineEdit_4->text(); QString surname = ui->lineEdit_5->text(); QString number = ui->lineEdit_6->text(); u.setData(name, surname, number); query->prepare("insert into TelephoneBook(Name, Surname,Number) values ('" + name + "', '" + surname + "', '" + number + "')"); if(query->exec()){ cout << "All done" << endl; db.close(); } MyItem *myitem = new MyItem(name, number); ui->listWidget->addItem(item); item->setSizeHint(QSize(0,70)); ui->listWidget->setItemWidget(item, myitem); ui->tabWidget->setCurrentWidget(ui->tab); }
and in terminal returned this error:
Data opened QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed. Data opened
You must not open a database twice. Please follow the documentation on how to open and use a QSqlDatabase: https://doc.qt.io/qt-6/qsqldatabase.html#details
-
You must not open a database twice. Please follow the documentation on how to open and use a QSqlDatabase: https://doc.qt.io/qt-6/qsqldatabase.html#details
wrote on 16 Apr 2023, 14:46 last edited by@Christian-Ehrlicher yeah I think I need to sleep, thank you for your help, I thought It would be easy creating simple project for University
1/11