66 auto *messageDialogHelper =
static_cast<QPlatformMessageDialogHelper *>(helper);
67 QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::checkBoxStateChanged, q,
68 [
this](Qt::CheckState state) {
69 again->setCheckState(state);
72 QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::clicked, q,
73 [
this](QPlatformDialogHelper::StandardButton, QPlatformDialogHelper::ButtonRole) {
83 auto *messageDialogHelper =
static_cast<QPlatformMessageDialogHelper *>(helper);
84 QSharedPointer<QMessageDialogOptions> options = QMessageDialogOptions::create();
85 options->setText(currentMessage);
86 options->setWindowTitle(q->windowTitle());
87 options->setText(QErrorMessage::tr(
"An error occurred"));
88 options->setInformativeText(currentMessage);
89 options->setStandardIcon(QMessageDialogOptions::Critical);
90 options->setCheckBox(again->text(), again->checkState());
91 messageDialogHelper->setOptions(options);
191static void jump(QtMsgType t,
const QMessageLogContext &context,
const QString &m)
193 const auto forwardToOriginalHandler = qScopeGuard([&] {
198 if (!qtMessageHandler)
201 auto *defaultCategory = QLoggingCategory::defaultCategory();
202 if (context.category && defaultCategory
203 && qstrcmp(context.category, defaultCategory->categoryName()) != 0)
206 QString rich =
"<p><b>"_L1 + msgType2i18nString(t) +
"</b></p>"_L1
207 + Qt::convertFromPlainText(m, Qt::WhiteSpaceNormal);
210 if (rich.endsWith(
"</p>"_L1))
214 if (QThread::isMainThread()) {
217 QMetaObject::invokeMethod(qtMessageHandler,
219 Qt::QueuedConnection,
220 Q_ARG(QString, rich));
222 metFatal = (t == QtFatalMsg);
236QErrorMessage::QErrorMessage(QWidget * parent)
237 : QDialog(*
new QErrorMessagePrivate, parent)
241#if defined(Q_OS_MACOS)
242 setWindowModality(parent ? Qt::WindowModal : Qt::ApplicationModal);
245 d->icon =
new QLabel(
this);
246 d->errors =
new QErrorMessageTextView(
this);
247 d->again =
new QCheckBox(
this);
248 d->ok =
new QPushButton(
this);
249 QGridLayout * grid =
new QGridLayout(
this);
251 connect(d->ok, SIGNAL(clicked()),
this, SLOT(accept()));
253 grid->addWidget(d->icon, 0, 0, Qt::AlignTop);
254 grid->addWidget(d->errors, 0, 1);
255 grid->addWidget(d->again, 1, 1, Qt::AlignTop);
256 grid->addWidget(d->ok, 2, 0, 1, 2, Qt::AlignCenter);
257 grid->setColumnStretch(1, 42);
258 grid->setRowStretch(0, 42);
260#if QT_CONFIG(messagebox)
261 const auto iconSize = style()->pixelMetric(QStyle::PM_MessageBoxIconSize,
nullptr,
this);
262 const auto icon = style()->standardIcon(QStyle::SP_MessageBoxInformation,
nullptr,
this);
263 d->icon->setPixmap(icon.pixmap(QSize(iconSize, iconSize), devicePixelRatio()));
264 d->icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
266 d->again->setChecked(
true);
269 d->retranslateStrings();
277QErrorMessage::~QErrorMessage()
279 if (
this == qtMessageHandler) {
280 qtMessageHandler =
nullptr;
281 QtMessageHandler currentMessagHandler = qInstallMessageHandler(
nullptr);
282 if (currentMessagHandler != jump)
283 qInstallMessageHandler(currentMessagHandler);
285 qInstallMessageHandler(originalMessageHandler);
286 originalMessageHandler =
nullptr;
293void QErrorMessage::done(
int a)
296 if (!d->again->isChecked()) {
297 if (d->currentType.isEmpty()) {
298 if (!d->currentMessage.isEmpty())
299 d->doNotShow.insert(d->currentMessage);
301 d->doNotShowType.insert(d->currentType);
304 d->currentMessage.clear();
305 d->currentType.clear();
309 if (d->nextPending()) {
312 if (
this == qtMessageHandler && metFatal)
352 while (!pending.empty()) {
353 QString message = std::move(pending.front().content);
354 QString type = std::move(pending.front().type);
356 if (isMessageToBeShown(message, type)) {
357#ifndef QT_NO_TEXTHTMLPARSER
358 errors->setHtml(message);
360 errors->setPlainText(message);
362 currentMessage = std::move(message);
363 currentType = std::move(type);
364 again->setChecked(
true);
399void QErrorMessage::showMessage(
const QString &message,
const QString &type)
402 if (!d->isMessageToBeShown(message, type))
404 d->pending.push({message, type});
405 if (!isVisible() && d->nextPending())