[Qt-interest] QWinWidget problem when using DeleteOnClose attribute

elizabeta petreska elizabeta.petreska at gmail.com
Wed Sep 23 11:41:28 CEST 2009


I found this one in Qt sources :

bool QWinWidget::eventFilter(QObject *o, QEvent *e)
{
..........................
case QEvent::Hide:
    if (reenable_parent) {
        EnableWindow(hParent, true);
        reenable_parent = false;
    }
    resetFocus();
        if (w->testAttribute(Qt::WA_DeleteOnClose) && w->isWindow())
        deleteLater();
.....
}

The showMinimized () function send hide event.

I am wondering what is the reason for making the QWinWidget to delete later
when it receives hide event.







On Wed, Sep 23, 2009 at 9:24 AM, elizabeta petreska <
elizabeta.petreska at gmail.com> wrote:

> Hello
>
> First of all, sorry if this is the wrong mailing list, just direct me where
> to post my question if it is.
>
> I am using Mfc to Qt Solution for showing Qt widgets in plugin dlls that
> are loaded in third party Mfc application.
> I am using the function QMfcApp::pluginInstance in my DllMain function to
> make the QApplication object.
>
> I reproduce the error on this very simple listing :
>
> class SimpleDlg : public QDialog,public Ui::Dlg
> {
> Q_OBJECT
>
> public:
>     SimpleDlg(QWidget* parent=0);
>     ~SimpleDlg(){}
>     private slots:
>     OnButtonClicked();
> };
>
> and in the implementation file :
>
> SimpleDlg::SimpleDlg(QWidget* parent):QDialog(parent)
> {
>     this ->setAttribute(Qt::WA_DeleteOnClose);
> }
>
> SimpleDlg::OnButtonClicked()
> {
>          1:      this->showMinimized();
>
>          2  :      MSG msg;
>          3:          PeekMessage( &msg, NULL, 0, 0,0 );
>
>          4:         lineEdit->setText("Crash"); //crashes here. If I
> comment line this->showMinimized() the crash doesnot happen
>
>          5:         this->showMaximized();
>
> }
>
> somewhere in the plugin dll :
>
> QWinWidget* win=new QWinWidget(MfcAppHandle);
> win->showCentered();
> SimpleDlg* dlg=new SimpleDlg(win);
> dlg->show();
>
> The crash is occuring in line 4, since the dialog is already deleted when
> the execution comes to that line.
> Also note that if I uncomment line 1 i.e showMinimized() the crash is not
> happening. The dialog is deleted after PeekMessage function, cause then the
> Qt message hook which is
> set with the Qt Mfc Migration Solution is executed.
>
> So the question is who is sending the DefferedDelete event, is it
> showMinimized () ? I was thinking that this event will be sent only
> when I close the dialog hence the name Qt::WA_DeleteOnClose.
>
> Also I don't think that the DefferedDelete event is send by showMinimized()
> cause this doesnot make sense at all. So when the DefferedDelete should be
> sent  normally and
> what could be the problem in my example ?
>
> Note that the when I show my dialog from regular Qt application i.e not Mfc
> everything is working as it should.
>
> Thank you for your time
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090923/9a105706/attachment.html 


More information about the Qt-interest-old mailing list