Cannot close application
-
I have an issue where various Qt quit methods (QApplication::quit(), QApplication::exit(), QCoreApplication::quit(), etc.) are not working when called. Only std::exit() seems to work.
Here's a minimal example demonstrating the issue:
void MyClass::runLicenseCheck() { QJsonParseError parseError; QJsonDocument doc = QJsonDocument::fromJson(licenseData, &parseError); if (parseError.error != QJsonParseError::NoError) { qDebug() << "Failed to parse JSON:" << parseError.errorString(); // None of these work: // QApplication::quit(); // QApplication::exit(1); // QCoreApplication::quit(); // qApp->quit(); // Only this works: std::exit(1); return; } }
How is this possible? Could somebody explain? Whats happening?
-
The Qt functions exit the Qt event loop. Invoked from your
main()
. You do not allow code to return to that so you don't see any effect, at least depending where you callrunLicenseCheck()
from.Don't directly exit the Qt application on some license check failure, Return a failure code, clean up somewhere, exit from your main program.
-
@joejack77 said in Cannot close application:
minimal example demonstrating the issue:
I don't think any
QJsonDocument
and other JSON stuff is relevant to demonstrate your issue.
The more important part is, what @JonB also mentioned, where do you call thisrunLicenseCheck
function and what happens before and after?