[Qt-interest] Unable to display QErrorMessage in modal dialog

Karsten Heimrich karsten.heimrich at nokia.com
Thu Jun 11 16:53:45 CEST 2009


Hi,

Stephen Collyer schrieb:
> I have the following code which is called after an OK button is
> clicked, in a modal dialog:
> 
> void InstallAgentSSLCertDlg::check_passphrase_data()
> {
>     QString pp_str  = passphrase->text();
>     QString cpp_str = confirm_passphrase->text();
> 
>     if (! pp_str.isEmpty() || ! cpp_str.isEmpty() &&
>         (pp_str != cpp_str))
>     {
>         QErrorMessage error;
>         error.showMessage(tr("The passphrase and confirmation differ"));
>     }
>     else
>     {
>         accept();
>     }
> }
> 
> I never see the QErrorMessage if the true branch of the if
> is taken. Can anyone tell me why this doesn't work ?

according to the documentation, 'showMessage(...)' shows the 
message and returns immediately. Thus your QErrorMessage object 
goes out of scope and will be destroyed. You should create the
QErrorMessage inside your dialogs constructor and set the dialog 
as parent.

http://doc.trolltech.com/latest/qerrormessage.html#showMessage


Regards,
-- 
Karsten Heimrich - karsten.heimrich (AT) nokia.com
Software Engineer - Nokia, Qt Software
Rudower Chaussee 13, 12489 Berlin, Germany



More information about the Qt-interest-old mailing list