Solved App crashes on model->rowCount()
-
The model is a QSqlTableModel. (declared this way: QSqlTableModel *manufacturers_tbl_model;)
In the clicked slot of a pushbutton, I have this code.void RepairDevices::on_manufacturers_add_btn_clicked() { int row = manufacturers_tbl_model->rowCount(); }
And when I click the button, the application just...crashes!!!
What am I doing wrong? -
It's hard to tell without more information such as a stack trace or complete example. By any chance is manufacturers_tbl_model uninitialized?
-
Hi,
Is manufacturers_tbl_model pointing to something valid ? i.e. did you do
manufacturers_tbl_model = new QSqlTableModel;
in the constructor or RepairDevices ? -
Hi guys.
Yes it is initialised:QSqlTableModel *manufacturers_tbl_model = new QSqlTableModel; manufacturers_tbl_model->setTable("manufacturers"); ui.manufacturers_tbl->setModel(manufacturers_tbl_model); manufacturers_tbl_model->select();
-
No it's not, you're shadowing your member variable.
-
What do you mean SGaist?
-
I replaced:
QSqlTableModel *manufacturers_tbl_model = new QSqlTableModel;
with:
manufacturers_tbl_model = new QSqlTableModel;
and does not crash anymore!!
Is this what you meant SGaist? -
Yes, that's what I meant.