prazuber
prazuber

Reputation: 1362

A way to forcefully close modal QFileDialog on Mac

I have a Qt application which at some point calls QFileDialog::getOpenFileName. However, at any point my application can get an event which will make this file dialog irrelevant, so I want to forcefully close it.

This is my way of trying to close this dialog:

QWidget *modalWidget = QApplication::activeModalWidget();
if (modalWidget)
    modalWidget->close();

This works on Windows, but I get strange behavior on Mac. Instead of closing, it hides the dialog instead. Execution never leaves QFileDialog::getOpenFileName call and since it's a modal dialog, underlying app becomes permanently frozen.

Upvotes: 2

Views: 208

Answers (1)

prazuber
prazuber

Reputation: 1362

For the sake of closure, I ended up closing the dialog by calling native [NSApp abortModal].

Note that this workaround might not be needed if this issue was fixed in the recent Qt releases (haven't checked since Qt 5.8).

Upvotes: 1

Related Questions