Assert raisied when closing multi-level modal dialog recursively
Assen Mladenov <[email protected]> Fri, 17 Apr 2026 00:47:54 -0700 (PDT)
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_355840_956828500.1776412074710
Content-Type: multipart/alternative;
boundary="----=_Part_355841_243228674.1776412074710"
------=_Part_355841_243228674.1776412074710
Content-Type: text/plain; charset="UTF-8"
Hi,
I need to close (stacked) modal dialogs programmatically and I try doing
that in a recursive fashion, starting from the one on top.
Here is the piece of code that is executed on the main event loop (the
app's):
static void closeAllDialogsRec(wxWindow* parent, wxApp *app) {
auto pclNode = parent->GetChildren().GetFirst();
while (pclNode) {
auto dlg = wxDynamicCast(pclNode->GetData(), wxDialog);
if (dlg && dlg->IsModal()) {
closeAllDialogsRec(dlg, app);
app->CallAfter([dlg, app]() mutable {
wxCommandEvent evt(wxEVT_CLOSE_WINDOW);
wxQueueEvent(dlg, evt.Clone());
});
break;
}
pclNode = pclNode->GetNext();
}
}
The issue is that the top one's event loop is active and it can be closed,
but the for the others below, their event loops are still inactive and it
fails for them. So on theory, we have to wait until the next dialog becomes
"active" and then close it only then. How though ?
There is extra info in https://forums.wxwidgets.org/viewtopic.php?t=50669
Best regards,
Assen
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/69a78301-3976-41a5-9986-1d4e62177d1fn%40googlegroups.com.
------=_Part_355841_243228674.1776412074710
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<span style=3D"color: rgb(0, 0, 0); font-family: Tahoma, sans-serif;">Hi,</=
span><div style=3D"padding: 0px; margin: 0px; color: rgb(0, 0, 0); font-fam=
ily: Tahoma, sans-serif;">I need to close (stacked) modal dialogs programma=
tically and I try doing that in a recursive fashion, starting from the one =
on top.</div><div style=3D"padding: 0px; margin: 0px; color: rgb(0, 0, 0); =
font-family: Tahoma, sans-serif;"><br style=3D"padding: 0px; margin: 0px;" =
/></div><div style=3D"padding: 0px; margin: 0px; color: rgb(0, 0, 0); font-=
family: Tahoma, sans-serif;">Here is the piece of code that is executed on =
the main event loop (the app's):</div><div style=3D"padding: 0px; margin: 0=
px; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif;"><br style=3D"pad=
ding: 0px; margin: 0px;" /></div><div style=3D"padding: 0px; margin: 0px;">=
<div style=3D"padding: 0px; margin: 0px;"><font face=3D"Courier New" color=
=3D"#008000">static void closeAllDialogsRec(wxWindow* parent, wxApp *app) {=
</font></div><div style=3D"padding: 0px; margin: 0px;"><font face=3D"Courie=
r New" color=3D"#008000">=C2=A0 =C2=A0 auto pclNode =3D parent->GetChild=
ren().GetFirst();</font></div><div style=3D"padding: 0px; margin: 0px;"><fo=
nt face=3D"Courier New" color=3D"#008000">=C2=A0 =C2=A0 while (pclNode) {</=
font></div><div style=3D"padding: 0px; margin: 0px;"><font face=3D"Courier =
New" color=3D"#008000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 auto dlg =3D wxDynamicCa=
st(pclNode->GetData(), wxDialog);</font></div><div style=3D"padding: 0px=
; margin: 0px;"><font face=3D"Courier New" color=3D"#008000">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 if (dlg && dlg->IsModal()) {</font></div><div styl=
e=3D"padding: 0px; margin: 0px;"><font face=3D"Courier New" color=3D"#00800=
0">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 closeAllDialogsRec(dlg, app);<=
/font></div><div style=3D"padding: 0px; margin: 0px;"><font face=3D"Courier=
New" color=3D"#008000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 app->C=
allAfter([dlg, app]() mutable {</font></div><div style=3D"padding: 0px; mar=
gin: 0px;"><font face=3D"Courier New" color=3D"#008000">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wxCommandEvent evt(wxEVT_CLOSE_WINDO=
W);</font></div><div style=3D"padding: 0px; margin: 0px;"><font face=3D"Cou=
rier New" color=3D"#008000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 wxQueueEvent(dlg, evt.Clone());</font></div><div style=3D"paddin=
g: 0px; margin: 0px;"><font face=3D"Courier New" color=3D"#008000">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 });</font></div><div style=
=3D"padding: 0px; margin: 0px;"><font face=3D"Courier New" color=3D"#008000=
">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;</font></div><div style=
=3D"padding: 0px; margin: 0px;"><font face=3D"Courier New" color=3D"#008000=
">=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</font></div><div style=3D"padding: 0px; mar=
gin: 0px;"><font face=3D"Courier New" color=3D"#008000">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 pclNode =3D pclNode->GetNext();</font></div><div style=3D"pad=
ding: 0px; margin: 0px;"><font face=3D"Courier New" color=3D"#008000">=C2=
=A0 =C2=A0 }</font></div><div style=3D"padding: 0px; margin: 0px;"><font fa=
ce=3D"Courier New" color=3D"#008000">}</font></div></div><div style=3D"padd=
ing: 0px; margin: 0px; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif=
;"><br style=3D"padding: 0px; margin: 0px;" /></div><div style=3D"padding: =
0px; margin: 0px; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif;">Th=
e issue is that the top one's event loop is active and it can be closed, bu=
t the for the others below, their event loops are still inactive and it fai=
ls for them. So on theory, we have to wait until the next dialog becomes "a=
ctive" and then close it only then. How though ?</div><div style=3D"padding=
: 0px; margin: 0px; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif;">=
<br style=3D"padding: 0px; margin: 0px;" /></div><div style=3D"padding: 0px=
; margin: 0px; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif;">There=
is extra info in=C2=A0=C2=A0<a href=3D"https://forums.wxwidgets.org/viewto=
pic.php?t=3D50669" target=3D"_blank" rel=3D"nofollow" style=3D"padding: 0px=
; margin: 0px;">https://forums.wxwidgets.org/viewtopic.php?t=3D50669</a></d=
iv><div style=3D"padding: 0px; margin: 0px; color: rgb(0, 0, 0); font-famil=
y: Tahoma, sans-serif;"><br style=3D"padding: 0px; margin: 0px;" /></div><d=
iv style=3D"padding: 0px; margin: 0px; color: rgb(0, 0, 0); font-family: Ta=
homa, sans-serif;">Best regards,</div><div style=3D"padding: 0px; margin: 0=
px; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif;">Assen</div>
<p></p>
-- <br />
Please read <a href=3D"https://www.wxwidgets.org/support/mlhowto.htm">https=
://www.wxwidgets.org/support/mlhowto.htm</a> before posting.<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wx-users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wx-users+u=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
wx-users/69a78301-3976-41a5-9986-1d4e62177d1fn%40googlegroups.com?utm_mediu=
m=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/wx-users/6=
9a78301-3976-41a5-9986-1d4e62177d1fn%40googlegroups.com</a>.<br />
------=_Part_355841_243228674.1776412074710--
------=_Part_355840_956828500.1776412074710--