QMessageBox: use optional<> instead of unique_ptr

... to hold the optional QApplication.

Saves a memory allocation, and is more readable.

Amends 408fbd3f2d.

Pick-to: 6.6
Change-Id: I390b9cfa367d01feb59bb5deadc5383c8e678749
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
bb10
Marc Mutz 2023-06-21 07:44:10 +02:00
parent 1e626c135b
commit 2389b93b79
1 changed files with 3 additions and 3 deletions

View File

@ -39,7 +39,7 @@
#include <qpa/qplatformnativeinterface.h>
#endif
#include <memory>
#include <optional>
QT_BEGIN_NAMESPACE
@ -2853,9 +2853,9 @@ Q_WIDGETS_EXPORT void _q_requireVersion(int argc, char *argv[], QAnyStringView r
const auto current = QVersionNumber::fromString(qVersion()).normalized();
if (current >= required)
return;
std::unique_ptr<QApplication> application;
std::optional<QApplication> application;
if (!qApp)
application = std::make_unique<QApplication>(argc, argv);
application.emplace(argc, argv);
const QString message = QApplication::tr("Application \"%1\" requires Qt %2, found Qt %3.")
.arg(qAppName(), required.toString(), current.toString());
QMessageBox::critical(nullptr, QApplication::tr("Incompatible Qt Library Error"),