PDA

View Full Version : using a model view on a "local" dialog causes a seg fault on close



knobby67
28th August 2014, 18:32
Hi All,
I open a "local" dialog from my mainwindow. Using


Add_Dialog madd_dialog;

madd_dialog.setModal( true );
madd_dialog.exec( );


everything works fine however when I go to close it I get a segmentation fault.
On commenting out everything except the constructor and de-constructor I've found that putting a model in my class produces the crash, so my class shows


private:
Ui::Add_Dialog *ui;

// QStandardItemModel model;



if I comment out model it works fine. I presume this is something to do with memory however am not knowledge of Qt is not enough to work out the issue.

Also related to this does the debugger have a backtrace like ddd so when I get a seg fault I can see what's causing it.


Thanks

anda_skoa
28th August 2014, 18:53
If you have a crash, then the stack trace of that crash is a valuable source of information on where it actually crashed.

Cheers,
_

P.S. no need to set modality, QDialog::exec() does that already

knobby67
29th August 2014, 17:55
Hi,
in Qt the stack shows "0 ??" from ddd "#0 0x00000000 in ?? ()" also in ddd backtrace normally shows all your function calls on the stack and I can set an execution point in the function then just step to the seg fault. However again backtrace just shows #0 0x0000000 in ??(). To be honest I've never seen this before, can anyone advise on this. The error occurs when I close a dialog with either the x button or calling this->close. I f I comment out the model from the class the error doesn't happen. Thanks

wysota
29th August 2014, 18:41
Maybe your code is built in release mode and thus no trace is available. Or maybe the stack is corrupted. The code should not crash just because you have a model as a member variable. Did you try rebuilding the project?

knobby67
30th August 2014, 12:05
Ok solved it, when I set up the dialog I use


madd_dialog.setModal( true );
madd_dialog.exec( );

if I comment out setmodel it works. Don't know why as the tutorials I'm following always call this function. I only commented out because of anda's advise that it's not needed. However this seems to have go everything working. No idea why don't know enough about Qt.