comboBox->additem() crash application..
-
if (cl.exec()) { msg.setText("QUI"); msg.exec(); cl.first(); if (cl.first()) { msg.setText("OK"); msg.exec(); } do { ui->comboBox_Cliente->addItem(cl.value(0).toString()); } while (cl.next()); }
messagebox will appear with OK message
if i replace additem with messagebox all works correctly
Hi
Super.
Try
QString test=cl.value(0).toString();
and see if it crash on that line instead.
else it must mean
ui->comboBox_Cliente is not valid pointer. -
I know this does not address your problem but it should solve it anyway. Replace all your code with:
QSqlQueryModel* queryModel = new QSqlQueryModel(this); queryModel.setQuery(QStringLiteral("Select RAGSOC from CLIENTI order by RAGSOC ASC")); if(dynamic_cast<QSqlQueryModel*>(ui->comboBox_Cliente->model())) ui->comboBox_Cliente->model()->deleteLater(); ui->comboBox_Cliente->setModel(queryModel);
-
Hi
Super.
Try
QString test=cl.value(0).toString();
and see if it crash on that line instead.
else it must mean
ui->comboBox_Cliente is not valid pointer. -
I know this does not address your problem but it should solve it anyway. Replace all your code with:
QSqlQueryModel* queryModel = new QSqlQueryModel(this); queryModel.setQuery(QStringLiteral("Select RAGSOC from CLIENTI order by RAGSOC ASC")); if(dynamic_cast<QSqlQueryModel*>(ui->comboBox_Cliente->model())) ui->comboBox_Cliente->model()->deleteLater(); ui->comboBox_Cliente->setModel(queryModel);
-
@mrjj i've tried and crash on additem()..
comboBox is not a pointer .. i've create it with designer in the ui
Hi! Actually in designer it creates pointers,
ui->
is thenamespace
, andcomboBox_Cliente->
is aC++ pointer
. What is the error message when it crashes? -
Hi! Actually in designer it creates pointers,
ui->
is thenamespace
, andcomboBox_Cliente->
is aC++ pointer
. What is the error message when it crashes?in application output :
18:45:34: The process was ended forcefully.
18:45:34: /Users/matteo/Desktop/C++/QT/EasyGest/build-EasyGest-Desktop_Qt_5_11_2_clang_64bit18-Release/EasyGest.app/Contents/MacOS/EasyGest crashed. -
in the constructor of your class, can you add
QObject::connect(ui->comboBox_Cliente,&Qobject::destroyed,[]()->void{qDebug("Something exploded");});
?If you see the output it means you are deleting your ui before reusing it
-
in the constructor of your class, can you add
QObject::connect(ui->comboBox_Cliente,&Qobject::destroyed,[]()->void{qDebug("Something exploded");});
?If you see the output it means you are deleting your ui before reusing it
-
@VRonin said in comboBox->additem() crash application..:
in the constructor of your class
-
One more try, add
QObject::connect(this,&QObject::destroyed,[]()->void{qDebug("Something big exploded");});
and see if you have any output when you crash the application -
in application output :
18:45:34: The process was ended forcefully.
18:45:34: /Users/matteo/Desktop/C++/QT/EasyGest/build-EasyGest-Desktop_Qt_5_11_2_clang_64bit18-Release/EasyGest.app/Contents/MacOS/EasyGest crashed.This crash happens after you
addItem()
to theui->comboBox_Cliente
?Try to change the code to:
if (cl.exec()) { msg.setText("QUI"); msg.exec(); if (cl.first()) { msg.setText("OK"); msg.exec(); } do { ui->comboBox_Cliente->addItem(cl.value(0).toString()); } while (cl.next()); }
and check if it still crashes?
-
Hi,
i've populated from database n.1 comboBox and all is OKif i click on Annulla pushbutton (this is the code):
void inserisciarticolo::on_pushButton_Annulla_clicked() { // ANNULLA if (aDatabase.open()) { aDatabase.close(); } close(); }
and try to re-load the dialog (from application menu)
after first record of database additem() crashes the application
if i comment the additem() all works
this is the code i've used to load the comboBox data:
QSqlQuery cl; cl.prepare("Select RAGSOC from CLIENTI order by RAGSOC ASC"); ui->comboBox_Cliente->clear(); if (cl.exec()) { cl.first(); do { ui->comboBox_Cliente->addItem(cl.value(0).toString()); } while (cl.next()); }
ideas??
Thanks in advance.
-
@TheCipo76 said in comboBox->additem() crash application..:
you mean the os x crash report??
Nope, the stack trace which is a log of all the functions called up to the point of crash. If you use Qt Creator, see http://doc.qt.io/qtcreator/creator-debug-mode.html#viewing-call-stack-trace
-
@TheCipo76
Do you sit inside Qt Creator and run your app from within there via the debugger? We are expecting that when something "crashes", the debugger will catch that and show a stacktrace of exactly where it was in your code.