Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, July 2007
Core dump in itemDoubleClicked


Message 1 in thread

I have a very complex application which manages the display of modeless 
dialogs and windows.  It utilizes the close event to to manage the 
lifetime of the dialogs and windows.  I am having a problem with one 
dialog which ties the itemDoubleClicked signal from a list to the close 
slot of the dialog (hence a close event is generated), which is core 
dumping.  I've created a small reproducer of the problem, which is 
attached.  I'm working with Qt 4.3.0 on Linux (commerical version).

The reproducer does the following:

A modeless dialog (with a list inside and a close button) is parented by 
a top level window that has an event filter.  In the event filter, if 
the close event comes in, the dialog is deleted.  The dialog connects 
its "close" button to the close slot and this all works fine.

But when the list's itemDoubleClicked signal is connected to the close 
slot, core dump.  Any idea why?  I suspect that since I delete the 
dialog, the Qt double click processing wants to carry on with a list 
that is now gone.

Using double click on a list to perform "select + apply + close" is a 
pretty common operation and something that I really need to work. 

Below is the stack dump of the crash:
#0  0x00000000 in ?? ()
#1  0xb7d41f60 in QAbstractItemView::mouseDoubleClickEvent 
(this=0x814a0f8, event=0xbf9db184) at itemviews/qabstractitemview.cpp:1537
#2  0xb79425ea in QWidget::event (this=0x814a0f8, event=0xbf9db184) at 
kernel/qwidget.cpp:6033
#3  0xb7c3693b in QFrame::event (this=0x814a0f8, e=0xbf9db184) at 
widgets/qframe.cpp:640
#4  0xb7cc0829 in QAbstractScrollArea::viewportEvent (this=0x80c4d20, 
e=0xbf9db184) at widgets/qabstractscrollarea.cpp:903
#5  0xb7d4b0aa in QAbstractItemView::viewportEvent (this=0x814a0f8, 
event=0xbf9db184) at itemviews/qabstractitemview.cpp:1333
#6  0xb7cc3302 in QAbstractScrollAreaFilter::eventFilter 
(this=0x814a0f8, o=0x8143b48, e=0xbf9db184) at 
widgets/qabstractscrollarea_p.h:78
#7  0xb78fbf83 in QApplicationPrivate::notify_helper (this=0x804d180, 
receiver=0x8143b48, e=0xbf9db184) at kernel/qapplication.cpp:3528
#8  0xb78ff64c in QApplication::notify (this=0xbf9db784, 
receiver=0x8143b48, e=0xbf9db184) at kernel/qapplication.cpp:3235
#9  0xb753f40c in QCoreApplication::notifyInternal (this=0xbf9db784, 
receiver=0x8143b48, event=0xbf9db184) at kernel/qcoreapplication.cpp:507
#10 0xb7959004 in QETWidget::translateMouseEvent (this=0x8143b48, 
event=0xbf9db47c) at 
../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:187
#11 0xb795883d in QApplication::x11ProcessEvent (this=0xbf9db784, 
event=0xbf9db47c) at kernel/qapplication_x11.cpp:2900
#12 0xb797bc52 in x11EventSourceDispatch (s=0x8054088, callback=0, 
user_data=0x0) at kernel/qguieventdispatcher_glib.cpp:120
#13 0xb73cf7cf in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0

When I look at the code for frame 12, I see:
115
116             // send through event filter
117             if (source->q->filterEvent(&event))
118                 continue;
119
120             if (qApp->x11ProcessEvent(&event) == 1)
121                 return true;
122
123             if (event.xany.serial >= marker)
124                 goto out;

Notice that the event is sent to any filters (where I'm deleting the 
dialog), and is then sent off to qApp for processing.  I think this may 
be the problem.  Any help is greatly appreciated. 

Thanks in advance,
Susan Macchia



---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.

#include <QtGui>
#include <QtGui>

#include "MyWin.h"

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    MyWin *win = new MyWin(); 
    
    win->show();
    return app.exec();
}
#include "MyWin.h"
#include "MyWin.h"


//*****************************************************************************
//
MyWin::MyWin(QWidget *parent)
  :
    QWidget(parent),
    
    db(NULL)
{
    QVBoxLayout *vbl = new QVBoxLayout();
    setLayout(vbl);
    
    QPushButton *button = new QPushButton("Show Dialog");
    vbl->addWidget(button);
    
    connect(button, SIGNAL(clicked()), this, SLOT(showDialog()));
}


void MyWin::showDialog()
{
    if (db)
    {
        db->show();
        return;
    }
    
    db = new MyDialog(this);
    db->installEventFilter(this);
    db->show();
}


bool MyWin::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::Close && obj == db)
    {
        delete db; db = NULL;
        return true;
    }
    
    return false;
}


//*****************************************************************************
//
MyDialog::MyDialog(QWidget *parent)
  :
    QDialog(parent)
{
    QVBoxLayout *vbl = new QVBoxLayout();
    setLayout(vbl);
    
    QListWidget *list = new QListWidget();
    vbl->addWidget(list);
    
    QString prefix("Item #");
    for (int i = 1; i <= 20; i++)
    {
        QString name = prefix + QString::number(i);
        list->addItem(name);
    }
    
    connect(
        list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), 
        this, SLOT(close()));
    
    
    QPushButton *button = new QPushButton("Close");
    vbl->addWidget(button);
    connect(button, SIGNAL(clicked()), this, SLOT(close()));
}


void MyDialog::doubleClick()
{
}

#ifndef _MYWIN
#ifndef _MYWIN
#define _MYWIN

#include <QtGui>


class MyWin : public QWidget
{
    Q_OBJECT

public:
    MyWin(QWidget *parent = NULL);
    virtual ~MyWin() {}
    
protected:
    virtual bool eventFilter(QObject *obj, QEvent *event);


private slots:
    void showDialog();
    
private:
    QDialog *db;
};



class MyDialog : public QDialog
{
    Q_OBJECT

public:
    MyDialog(QWidget *parent = NULL);
    virtual ~MyDialog() {}
    
private slots:
    void doubleClick();
    
private:
};



#endif // _MYWIN

Message 2 in thread

I haven't looked at your specific code here, but I do have one standard trick 
that might help you here: Instead of deleting the dialog, do a deleteLater(). 
This will delete the dialog in the event loop, and means all slots, etc. will 
have done their work.

Bo.

On onsdag den 25. Juli 2007, Susan Macchia wrote:
> I have a very complex application which manages the display of modeless
> dialogs and windows.  It utilizes the close event to to manage the
> lifetime of the dialogs and windows.  I am having a problem with one
> dialog which ties the itemDoubleClicked signal from a list to the close
> slot of the dialog (hence a close event is generated), which is core
> dumping.  I've created a small reproducer of the problem, which is
> attached.  I'm working with Qt 4.3.0 on Linux (commerical version).
>
> The reproducer does the following:
>
> A modeless dialog (with a list inside and a close button) is parented by
> a top level window that has an event filter.  In the event filter, if
> the close event comes in, the dialog is deleted.  The dialog connects
> its "close" button to the close slot and this all works fine.
>
> But when the list's itemDoubleClicked signal is connected to the close
> slot, core dump.  Any idea why?  I suspect that since I delete the
> dialog, the Qt double click processing wants to carry on with a list
> that is now gone.
>
> Using double click on a list to perform "select + apply + close" is a
> pretty common operation and something that I really need to work.
>
> Below is the stack dump of the crash:
> #0  0x00000000 in ?? ()
> #1  0xb7d41f60 in QAbstractItemView::mouseDoubleClickEvent
> (this=0x814a0f8, event=0xbf9db184) at itemviews/qabstractitemview.cpp:1537
> #2  0xb79425ea in QWidget::event (this=0x814a0f8, event=0xbf9db184) at
> kernel/qwidget.cpp:6033
> #3  0xb7c3693b in QFrame::event (this=0x814a0f8, e=0xbf9db184) at
> widgets/qframe.cpp:640
> #4  0xb7cc0829 in QAbstractScrollArea::viewportEvent (this=0x80c4d20,
> e=0xbf9db184) at widgets/qabstractscrollarea.cpp:903
> #5  0xb7d4b0aa in QAbstractItemView::viewportEvent (this=0x814a0f8,
> event=0xbf9db184) at itemviews/qabstractitemview.cpp:1333
> #6  0xb7cc3302 in QAbstractScrollAreaFilter::eventFilter
> (this=0x814a0f8, o=0x8143b48, e=0xbf9db184) at
> widgets/qabstractscrollarea_p.h:78
> #7  0xb78fbf83 in QApplicationPrivate::notify_helper (this=0x804d180,
> receiver=0x8143b48, e=0xbf9db184) at kernel/qapplication.cpp:3528
> #8  0xb78ff64c in QApplication::notify (this=0xbf9db784,
> receiver=0x8143b48, e=0xbf9db184) at kernel/qapplication.cpp:3235
> #9  0xb753f40c in QCoreApplication::notifyInternal (this=0xbf9db784,
> receiver=0x8143b48, event=0xbf9db184) at kernel/qcoreapplication.cpp:507
> #10 0xb7959004 in QETWidget::translateMouseEvent (this=0x8143b48,
> event=0xbf9db47c) at
> ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:187
> #11 0xb795883d in QApplication::x11ProcessEvent (this=0xbf9db784,
> event=0xbf9db47c) at kernel/qapplication_x11.cpp:2900
> #12 0xb797bc52 in x11EventSourceDispatch (s=0x8054088, callback=0,
> user_data=0x0) at kernel/qguieventdispatcher_glib.cpp:120
> #13 0xb73cf7cf in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
>
> When I look at the code for frame 12, I see:
> 115
> 116             // send through event filter
> 117             if (source->q->filterEvent(&event))
> 118                 continue;
> 119
> 120             if (qApp->x11ProcessEvent(&event) == 1)
> 121                 return true;
> 122
> 123             if (event.xany.serial >= marker)
> 124                 goto out;
>
> Notice that the event is sent to any filters (where I'm deleting the
> dialog), and is then sent off to qApp for processing.  I think this may
> be the problem.  Any help is greatly appreciated.
>
> Thanks in advance,
> Susan Macchia
>
>
>
> ---
>
> This communication contains confidential information. If you are not the
> intended recipient please return this email to the sender and delete it
> from your records.
>
> Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der
> beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den
> Absender zurück und löschen Sie die E-mail aus Ihrem System.



-- 
 [ signature omitted ] 

Message 3 in thread

Thanks - that did the trick :)

Bo Thorsen wrote:
> I haven't looked at your specific code here, but I do have one standard trick 
> that might help you here: Instead of deleting the dialog, do a deleteLater(). 
> This will delete the dialog in the event loop, and means all slots, etc. will 
> have done their work.
>
> Bo.
>
> On onsdag den 25. Juli 2007, Susan Macchia wrote:
>   
>> I have a very complex application which manages the display of modeless
>> dialogs and windows.  It utilizes the close event to to manage the
>> lifetime of the dialogs and windows.  I am having a problem with one
>> dialog which ties the itemDoubleClicked signal from a list to the close
>> slot of the dialog (hence a close event is generated), which is core
>> dumping.  I've created a small reproducer of the problem, which is
>> attached.  I'm working with Qt 4.3.0 on Linux (commerical version).
>>
>> The reproducer does the following:
>>
>> A modeless dialog (with a list inside and a close button) is parented by
>> a top level window that has an event filter.  In the event filter, if
>> the close event comes in, the dialog is deleted.  The dialog connects
>> its "close" button to the close slot and this all works fine.
>>
>> But when the list's itemDoubleClicked signal is connected to the close
>> slot, core dump.  Any idea why?  I suspect that since I delete the
>> dialog, the Qt double click processing wants to carry on with a list
>> that is now gone.
>>
>> Using double click on a list to perform "select + apply + close" is a
>> pretty common operation and something that I really need to work.
>>
>> Below is the stack dump of the crash:
>> #0  0x00000000 in ?? ()
>> #1  0xb7d41f60 in QAbstractItemView::mouseDoubleClickEvent
>> (this=0x814a0f8, event=0xbf9db184) at itemviews/qabstractitemview.cpp:1537
>> #2  0xb79425ea in QWidget::event (this=0x814a0f8, event=0xbf9db184) at
>> kernel/qwidget.cpp:6033
>> #3  0xb7c3693b in QFrame::event (this=0x814a0f8, e=0xbf9db184) at
>> widgets/qframe.cpp:640
>> #4  0xb7cc0829 in QAbstractScrollArea::viewportEvent (this=0x80c4d20,
>> e=0xbf9db184) at widgets/qabstractscrollarea.cpp:903
>> #5  0xb7d4b0aa in QAbstractItemView::viewportEvent (this=0x814a0f8,
>> event=0xbf9db184) at itemviews/qabstractitemview.cpp:1333
>> #6  0xb7cc3302 in QAbstractScrollAreaFilter::eventFilter
>> (this=0x814a0f8, o=0x8143b48, e=0xbf9db184) at
>> widgets/qabstractscrollarea_p.h:78
>> #7  0xb78fbf83 in QApplicationPrivate::notify_helper (this=0x804d180,
>> receiver=0x8143b48, e=0xbf9db184) at kernel/qapplication.cpp:3528
>> #8  0xb78ff64c in QApplication::notify (this=0xbf9db784,
>> receiver=0x8143b48, e=0xbf9db184) at kernel/qapplication.cpp:3235
>> #9  0xb753f40c in QCoreApplication::notifyInternal (this=0xbf9db784,
>> receiver=0x8143b48, event=0xbf9db184) at kernel/qcoreapplication.cpp:507
>> #10 0xb7959004 in QETWidget::translateMouseEvent (this=0x8143b48,
>> event=0xbf9db47c) at
>> ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:187
>> #11 0xb795883d in QApplication::x11ProcessEvent (this=0xbf9db784,
>> event=0xbf9db47c) at kernel/qapplication_x11.cpp:2900
>> #12 0xb797bc52 in x11EventSourceDispatch (s=0x8054088, callback=0,
>> user_data=0x0) at kernel/qguieventdispatcher_glib.cpp:120
>> #13 0xb73cf7cf in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
>>
>> When I look at the code for frame 12, I see:
>> 115
>> 116             // send through event filter
>> 117             if (source->q->filterEvent(&event))
>> 118                 continue;
>> 119
>> 120             if (qApp->x11ProcessEvent(&event) == 1)
>> 121                 return true;
>> 122
>> 123             if (event.xany.serial >= marker)
>> 124                 goto out;
>>
>> Notice that the event is sent to any filters (where I'm deleting the
>> dialog), and is then sent off to qApp for processing.  I think this may
>> be the problem.  Any help is greatly appreciated.
>>
>> Thanks in advance,
>> Susan Macchia
>>
>>
>>
>> ---
>>
>> This communication contains confidential information. If you are not the
>> intended recipient please return this email to the sender and delete it
>> from your records.
>>
>> Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der
>> beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den
>> Absender zurück und löschen Sie die E-mail aus Ihrem System.
>>     
>
>
>
>   


---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.