Results 1 to 8 of 8

Thread: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    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:
    Qt Code:
    1. Function: _ZN17QAbstractItemView21mouseDoubleClickEventEP11QMouseEvent
    2. 0x7ffff791bff6 <+0x01f6> or $0xe8ef8948,%eax
    3. 0x7ffff791bffb <+0x01fb> jno 0x7ffff791bf80 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11QMouseEvent+384>
    4. 0x7ffff791bffd <+0x01fd> (bad)
    5. 0x7ffff791bfff <+0x01ff> jmpq 0x7ffff791bf52 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11QMouseEvent+338>
    6. 0x7ffff791c004 <+0x0204> mov (%rbx),%rax
    7. 0x7ffff791c007 <+0x0207> mov %rbp,%rdi
    8. 0x7ffff791c00a <+0x020a> mov 0x2d0(%rax),%r13
    9. 0x7ffff791c011 <+0x0211> callq 0x7ffff76c43c0 <_ZNK21QPersistentModelIndexcvRK11QModelIndexEv@plt>
    10. 0x7ffff791c016 <+0x0216> mov %r12,%rcx
    11. 0x7ffff791c019 <+0x0219> mov $0x2,%edx
    12. 0x7ffff791c01e <+0x021e> mov %rax,%rsi
    13. 0x7ffff791c021 <+0x0221> mov %rbx,%rdi
    14. 0x7ffff791c024 <+0x0224> callq *%r13
    15. 0x7ffff791c027 <+0x0227> test %al,%al
    16. 0x7ffff791c029 <+0x0229> jne 0x7ffff791bff7 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11QMouseEvent+503>
    17. 0x7ffff791c02b <+0x022b> mov %rbx,%rdi
    18. 0x7ffff791c02e <+0x022e> callq 0x7ffff76fe5f0 <_ZNK7QWidget5styleEv>
    19. 0x7ffff791c033 <+0x0233> mov (%rax),%r9
    20. 0x7ffff791c036 <+0x0236> xor %r8d,%r8d
    21. 0x7ffff791c039 <+0x0239> xor %edx,%edx
    22. 0x7ffff791c03b <+0x023b> mov %rbx,%rcx
    23. 0x7ffff791c03e <+0x023e> mov $0x3d,%esi
    24. 0x7ffff791c043 <+0x0243> mov %rax,%rdi
    25. 0x7ffff791c046 <+0x0246> callq *0xf0(%r9)
    26. 0x7ffff791c04d <+0x024d> test %eax,%eax
    27. 0x7ffff791c04f <+0x024f> jne 0x7ffff791bff7 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11QMouseEvent+503>
    28. 0x7ffff791c051 <+0x0251> mov %rbp,%rdi
    29. 0x7ffff791c054 <+0x0254> callq 0x7ffff76c43c0 <_ZNK21QPersistentModelIndexcvRK11QModelIndexEv@plt>
    30. 0x7ffff791c059 <+0x0259> mov %rbx,%rdi
    31. 0x7ffff791c05c <+0x025c> mov %rax,%rsi
    32. 0x7ffff791c05f <+0x025f> callq 0x7ffff791ae30 <_ZN17QAbstractItemView9activatedERK11QModelIndex>
    33. 0x7ffff791c064 <+0x0264> jmp 0x7ffff791bff7 <_ZN17QAbstractItemView21mouseDoubleClickEventEP11QMouseEvent+503>
    34. 0x7ffff791c066 <+0x0000> nopw %cs:0x0(%rax,%rax,1)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    Looks like you forgot to post the code of the slot connected to the signal.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    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:
    Qt Code:
    1. connect(table,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(rSelect(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 

    Here is the slot which in turns emits another signal so the QDialog know what data to extract:
    Qt Code:
    1. void ListaAng::rSelect(QModelIndex index){
    2. int rand=index.row();
    3. QString id=index.sibling(rand,0).data().toString();
    4. emit semnalAngSel(id);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Here I create the table and connect the semnalAngSel(QString) signal:
    Qt Code:
    1. void widget::tabelSql(QString tab){
    2. curatare(); //this is a function which cleans the layout
    3. if(tab=="lAng"){
    4. ListaAng *lAng=new ListaAng();
    5. connect(lAng,SIGNAL(semnalAngSel(QString)),this,SLOT(ferVizAng(QString)));
    6. layoutCentral->addWidget(lAng);
    7. lAng->selectPrimR();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    And here is where I call my Dialog:
    Qt Code:
    1. void widget::ferVizAng(QString id){
    2. FerDialAng *fda=new FerDialAng(this,id);
    3. connect(fda,SIGNAL(semnalAct(QString)),this,SLOT(tabelSql(QString))); //here I call the table to "refresh"
    4. fda->exec();
    5. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    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,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    adutzu89 (11th February 2014)

  6. #5
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    I will try tommorow. Thank you.

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    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.
    Qt Code:
    1. // QSqlQueryModel *model;
    2.  
    3. model->setQuery(model->query());
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to ChrisW67 for this useful post:

    adutzu89 (11th February 2014)

  9. #7
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    Quote Originally Posted by ChrisW67 View Post
    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.
    Qt Code:
    1. // QSqlQueryModel *model;
    2.  
    3. model->setQuery(model->query());
    To copy to clipboard, switch view to plain text mode 
    curatare() contains the following:
    Qt Code:
    1. QLayoutItem *child;
    2. while ((child = layoutCentral->takeAt(0)) != 0) {
    3. delete child->widget();
    4. delete child;
    5. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by adutzu89; 11th February 2014 at 08:36.

  10. #8
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Signal doubleClicked(QModelIndex) crashes application on next accepted() signal.

    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:

    Qt Code:
    1. QLayoutItem *child;
    2. while ((child = layoutCentral->takeAt(0)) != 0) {
    3. delete child->widget();
    4. delete child;
    5. }
    To copy to clipboard, switch view to plain text mode 


    Added after 32 minutes:


    Strangely when I set breakpoints, it doesn't crash until all operations are finished.
    Last edited by adutzu89; 20th March 2014 at 08:16.

Similar Threads

  1. Replies: 2
    Last Post: 28th December 2010, 09:59
  2. Replies: 4
    Last Post: 10th December 2009, 14:54
  3. QTableView doubleclicked event not working
    By sgmurphy19 in forum Qt Programming
    Replies: 6
    Last Post: 15th March 2009, 10:00
  4. QTreeView::doubleClicked(const QModelIndex&) signal
    By Vladimir in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2007, 09:25
  5. QTreeWidget and doubleClicked signal
    By becond in forum Newbie
    Replies: 1
    Last Post: 2nd March 2006, 06:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.