comboBox->additem() crash application..
-
wrote on 8 Nov 2018, 16:46 last edited by TheCipo76 11 Aug 2018, 16:51
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.
-
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.
Hi
Check if
cl.first(); returns true before using it. -
wrote on 8 Nov 2018, 16:59 last edited by TheCipo76 11 Aug 2018, 17:01
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
-
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. -
wrote on 8 Nov 2018, 17:07 last edited by
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
wrote on 8 Nov 2018, 17:27 last edited byHi! 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?wrote on 8 Nov 2018, 17:46 last edited by TheCipo76 11 Aug 2018, 17:47in 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. -
wrote on 8 Nov 2018, 17:53 last edited by
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
wrote on 8 Nov 2018, 18:03 last edited by@VRonin said in comboBox->additem() crash application..:
QObject::connect(ui->comboBox_Cliente,&Qobject::destroyed,->void{qDebug("Something exploded");});
i don't understand where i have to put it..
in the .h file
after Q_OBJECT ??
-
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
wrote on 8 Nov 2018, 18:04 last edited by@VRonin said in comboBox->additem() crash application..:
in the constructor of your class
-
@VRonin said in comboBox->additem() crash application..:
in the constructor of your class
-
wrote on 8 Nov 2018, 18:23 last edited by
And it still crashes? did you set
Qt::WA_DeleteOnClose
? -
wrote on 8 Nov 2018, 18:34 last edited by
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 -
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 applicationwrote on 8 Nov 2018, 18:50 last edited by@VRonin said in comboBox->additem() crash application..:
QObject::connect(this,&QObject::destroyed,->void{qDebug("Something big exploded");});
no, i don't see any output..
-
wrote on 8 Nov 2018, 18:54 last edited by VRonin 11 Aug 2018, 19:14
This is turning into a mistery now. Can you post the stack trace at the moment of crash?
-
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.wrote on 8 Nov 2018, 19:35 last edited by Cobra91151 11 Aug 2018, 19:35This 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.
wrote on 8 Nov 2018, 19:44 last edited by JonB 11 Aug 2018, 19:47after first record of database additem() crashes the application
Has nobody yet asked you to run this in a debugger (e.g. from Qt Creator)? And give us the stacktrace? EDIT: Oh, @VRonin has 2 posts above. Please do so!
10/27