[Qt-interest] QWinWidget problem when using DeleteOnClose attribute
Robert Escott
robert at binarylogic.co.za
Wed Sep 23 20:40:06 CEST 2009
Hi Elizabetha
This might be a bit off the track of your question but in the example you gave, it looks like you are using an interface created by QtDesigner. I assume this because you're deriving from Ui:Dlg. If this is the case, you don't seem to be creating any of the widgets in the design. When uic creates the Ui::Dlg class, it creates a function called Ui::Dlg::setupUi(QWidget *parent) that you need to call in order to instantiate all the child widgets.
When I create dialogs using Qt Designer, this is the very first thing I do in the dialog constructor. Using your example below, I'd have done the constructor like this:
SimpleDlg::SimpleDlg(QWidget *parent):QDialog(this)
{
setupUi(this);
this->setAttribute(Qt::WA_DeleteOnClose);
}
This would explain the crash since lineEdit is not pointing to anything.
Robert
----- Original Message -----
From: elizabeta petreska
To: qt-interest at trolltech.com
Sent: Wednesday, September 23, 2009 9:24 AM
Subject: [Qt-interest] QWinWidget problem when using DeleteOnClose attribute
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/89fd73d3/attachment.html
More information about the Qt-interest-old
mailing list