Re: Assert raisied when closing multi-level modal dialog recursively
Vadim Zeitlin <[email protected]> Sat, 18 Apr 2026 15:09:59 +0200
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
--8323329-1069755936-1776517800=:3987
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-Disposition: INLINE
On Fri, 17 Apr 2026 00:47:54 -0700 (PDT) Assen Mladenov wrote:
AM> I need to close (stacked) modal dialogs programmatically and I try doing
AM> that in a recursive fashion, starting from the one on top.
Why can't you just call EndModal() if you have the pointers to all dialogs
already?
AM> Here is the piece of code that is executed on the main event loop (the
AM> app's):
AM>
AM> static void closeAllDialogsRec(wxWindow* parent, wxApp *app) {
AM> auto pclNode = parent->GetChildren().GetFirst();
AM> while (pclNode) {
AM> auto dlg = wxDynamicCast(pclNode->GetData(), wxDialog);
AM> if (dlg && dlg->IsModal()) {
AM> closeAllDialogsRec(dlg, app);
AM> app->CallAfter([dlg, app]() mutable {
AM> wxCommandEvent evt(wxEVT_CLOSE_WINDOW);
AM> wxQueueEvent(dlg, evt.Clone());
AM> });
AM> break;
AM> }
AM> pclNode = pclNode->GetNext();
AM> }
AM> }
AM>
AM> The issue is that the top one's event loop is active and it can be closed,
AM> but the for the others below, their event loops are still inactive and it
AM> fails for them. So on theory, we have to wait until the next dialog becomes
AM> "active" and then close it only then. How though ?
You probably need to close one dialog at a time, i.e. return to the main
event loop after closing the first dialog and then redoing it again as long
as there are more dialogs, but this risks being messy.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/
--8323329-1069755936-1776517800=:3987
Content-Type: APPLICATION/PGP-SIGNATURE
-----BEGIN PGP SIGNATURE-----
iF0EABECAB0WIQQx+vLQdOwioQqkxtoG6kHeT2wehgUCaeOCpwAKCRAG6kHeT2we
hkeXAJ9PgaE+RUQeWA/iZggzMfxr5UIJ0ACcD80/dTaiIwOxIikV9R0KrsPqxJo=
=PFlv
-----END PGP SIGNATURE-----
--8323329-1069755936-1776517800=:3987--