PDA

View Full Version : Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.



adutzu89
10th February 2014, 13:03
I have a table with model set to QSqlQueryModel, which acquires data from MySQL server.
I connected the doubleClicked signal to a slot so I can open a dialog with data of the selected row, on which I have a reject and accept button.
If I reject, there is no problem, the dialog closes, If I accept on the other hand, the whole app crashes.
Here is another thing that you need to know, for that table I added another shortcut which activates when pressing Return key and this issue does not occur when I open the dialog using the Return key, just when opening with doubleclick.

Here is what I get when using debugger:

Function: _ZN17QAbstractItemView21mouseDoubleClickEventEP11Q MouseEvent
0x7ffff791bff6 <+0x01f6> or $0xe8ef8948,%eax
0x7ffff791bffb <+0x01fb> jno 0x7ffff791bf80 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11Q MouseEvent+384>
0x7ffff791bffd <+0x01fd> (bad)
0x7ffff791bfff <+0x01ff> jmpq 0x7ffff791bf52 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11Q MouseEvent+338>
0x7ffff791c004 <+0x0204> mov (%rbx),%rax
0x7ffff791c007 <+0x0207> mov %rbp,%rdi
0x7ffff791c00a <+0x020a> mov 0x2d0(%rax),%r13
0x7ffff791c011 <+0x0211> callq 0x7ffff76c43c0 <_ZNK21QPersistentModelIndexcvRK11QModelIndexEv@plt>
0x7ffff791c016 <+0x0216> mov %r12,%rcx
0x7ffff791c019 <+0x0219> mov $0x2,%edx
0x7ffff791c01e <+0x021e> mov %rax,%rsi
0x7ffff791c021 <+0x0221> mov %rbx,%rdi
0x7ffff791c024 <+0x0224> callq *%r13
0x7ffff791c027 <+0x0227> test %al,%al
0x7ffff791c029 <+0x0229> jne 0x7ffff791bff7 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11Q MouseEvent+503>
0x7ffff791c02b <+0x022b> mov %rbx,%rdi
0x7ffff791c02e <+0x022e> callq 0x7ffff76fe5f0 <_ZNK7QWidget5styleEv>
0x7ffff791c033 <+0x0233> mov (%rax),%r9
0x7ffff791c036 <+0x0236> xor %r8d,%r8d
0x7ffff791c039 <+0x0239> xor %edx,%edx
0x7ffff791c03b <+0x023b> mov %rbx,%rcx
0x7ffff791c03e <+0x023e> mov $0x3d,%esi
0x7ffff791c043 <+0x0243> mov %rax,%rdi
0x7ffff791c046 <+0x0246> callq *0xf0(%r9)
0x7ffff791c04d <+0x024d> test %eax,%eax
0x7ffff791c04f <+0x024f> jne 0x7ffff791bff7 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11Q MouseEvent+503>
0x7ffff791c051 <+0x0251> mov %rbp,%rdi
0x7ffff791c054 <+0x0254> callq 0x7ffff76c43c0 <_ZNK21QPersistentModelIndexcvRK11QModelIndexEv@plt>
0x7ffff791c059 <+0x0259> mov %rbx,%rdi
0x7ffff791c05c <+0x025c> mov %rax,%rsi
0x7ffff791c05f <+0x025f> callq 0x7ffff791ae30 <_ZN17QAbstractItemView9activatedERK11QModelIndex>
0x7ffff791c064 <+0x0264> jmp 0x7ffff791bff7 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11Q MouseEvent+503>
0x7ffff791c066 <+0x0000> nopw %cs:0x0(%rax,%rax,1)

anda_skoa
10th February 2014, 13:49
Looks like you forgot to post the code of the slot connected to the signal.

Cheers,
_

adutzu89
10th February 2014, 14:44
Sorry :), I hope your not sick of me anda_skoa, I try looking on the docs and over the internet for solutions and I post whenever I can't find a solution.

Here is the connect statement:

connect(table,SIGNAL(doubleClicked(QModelIndex)),t his,SLOT(rSelect(QModelIndex)));

Here is the slot which in turns emits another signal so the QDialog know what data to extract:

void ListaAng::rSelect(QModelIndex index){
int rand=index.row();
QString id=index.sibling(rand,0).data().toString();
emit semnalAngSel(id);
}

Here I create the table and connect the semnalAngSel(QString) signal:

void widget::tabelSql(QString tab){
curatare(); //this is a function which cleans the layout
if(tab=="lAng"){
ListaAng *lAng=new ListaAng();
connect(lAng,SIGNAL(semnalAngSel(QString)),this,SL OT(ferVizAng(QString)));
layoutCentral->addWidget(lAng);
lAng->selectPrimR();
}
}

And here is where I call my Dialog:

void widget::ferVizAng(QString id){
FerDialAng *fda=new FerDialAng(this,id);
connect(fda,SIGNAL(semnalAct(QString)),this,SLOT(t abelSql(QString))); //here I call the table to "refresh"
fda->exec();
}

anda_skoa
10th February 2014, 15:37
Hmm, hard to tell.

Looks very strange, but nothing stands out as obviously wrong.

Can you break it down to a compilable project that you can attach as a ZIP file?

Cheers,
_

adutzu89
10th February 2014, 19:53
I will try tommorow. Thank you.

ChrisW67
11th February 2014, 06:03
Put a breakpoint in each of the functions: ListaAng::rSelect(), void widget::tabelSql, widget::ferVizAng() and curatare().
Run your program in the debugger. Single step until it crashes then you will know what your program did to deserve it.

My money is on whatever you are hiding in curatare().
Really though, refreshing the content of the table should involve causing the QSqlQueryModel to requery the data, not stuffing around with new widgets and layouts.


// QSqlQueryModel *model;

model->setQuery(model->query());

adutzu89
11th February 2014, 07:32
Put a breakpoint in each of the functions: ListaAng::rSelect(), void widget::tabelSql, widget::ferVizAng() and curatare().
Run your program in the debugger. Single step until it crashes then you will know what your program did to deserve it.

My money is on whatever you are hiding in curatare().
Really though, refreshing the content of the table should involve causing the QSqlQueryModel to requery the data, not stuffing around with new widgets and layouts.


// QSqlQueryModel *model;

model->setQuery(model->query());


curatare() contains the following:

QLayoutItem *child;
while ((child = layoutCentral->takeAt(0)) != 0) {
delete child->widget();
delete child;
}


Which removes any widgets that are in my central widget, but this is only called when I trigger menu actions and not when I refresh the table, I will try first your solution as is it now I am remaking the tableview entirely.
And it only cause my app to crash after calling rSelect(QModelIndex) from doubleClick, if I call it from shortcut(QKeySequence) it does not crash.


Update:

Solved the issue, thank you both.
I restructured my code, and now I am just resetting the query as you,ChrisW67, said; also as you both seen I was calling both tabelSql() and ferVizAng() from widget and when semnalAct(QString) signal was emited the app would do tabelSql()(trying to clean the central widget and remaking the whole table) all over again which here is where my app was crashing.

Now I moved the ferVizAng() slot inside table file and just reseting the query when I press the accept button.

Again thank you both for the assistance

adutzu89
20th March 2014, 08:16
I am "reviving" this thread with the question:
Am I cleaning the central layout properly?

I am needed to clean the layout(to add other widget) and like in the case mentioned above I get crashes when cleaning the central widget's layout, if the dialog was opened through double click and everytime it crashes at cleaning operation.
I use the same operation to do it:


QLayoutItem *child;
while ((child = layoutCentral->takeAt(0)) != 0) {
delete child->widget();
delete child;
}

Added after 32 minutes:

Strangely when I set breakpoints, it doesn't crash until all operations are finished.