Application hung after dialog opened during startup on macOS
-
My application's main contains:
deleteRemainingTempFiles(); mainWindow.show();if the dialog in deleteRemainingTempFiles() is displayed on macOS, then the application is unresponsive after clicking on "Yes".
Here's what's in deleteRemainingTempFiles()void deleteRemainingTempFiles() { ZFUNCTRACE_RUNTIME(); std::vector<QString> vFiles; qint64 totalSize = 0; QString folder(CAllStackingTasks::GetTemporaryFilesFolder()); QStringList nameFilters("DSS*.tmp"); QDir dir(folder); dir.setNameFilters(nameFilters); for (QFileInfo item : dir.entryInfoList()) { if (item.isFile()) { vFiles.emplace_back(item.absoluteFilePath()); totalSize += item.size(); } } if (!vFiles.empty()) { QString strMsg; QString strSize; ZTRACE_RUNTIME("Remove remaining %d temp files", vFiles.size()); SpaceToQString(totalSize, strSize); strMsg = QString("One or more temporary files created by DeepSkyStacker are still in the working directory." "\n\nDo you want to remove them?\n\n(%1 file(s) using %2)") .arg(vFiles.size()).arg(strSize); QMessageBox msgBox(QMessageBox::Question, QString(""), strMsg, (QMessageBox::Yes | QMessageBox::No)); msgBox.setDefaultButton(QMessageBox::Yes); if (QMessageBox::Yes == msgBox.exec()) { QFile file; for (size_t i = 0; i < vFiles.size(); i++) { file.setFileName(vFiles[i]); file.remove(); } }; }; };What am I doing wrong, and what do I need to do to fix this?
Thanks, David
-
IIRC, ALL Qt apps have to actually start the event loop running with a call to exec().
-
Hi,
Which version of Qt are you using ?
On which version of macOS ? -
@SGaist Qt 6.10, macOS Tahoe 26.3.1.
@Kent-Dorfman AFAIK, and I could be wrong, QMessageBox::exec() runs it own local event loop. -
@J.Hilk Yes, most certainly. QCoreApplication instance is created over a 100 lines earlier.
app.exec() is called immediately after mainWindow.show().The main window is fully displayed while that dialog is running. So it almost seems that the dlg operates asynchronously. -
@Perdrix said in Application hung after dialog opened during startup on macOS:
Hmmm Should I set that QMessageBox to be "application modal"?
@Perdrix As I understand your flow, yes, the dialog should be modal since it is first and exclusive before doing mainwindow processing.