summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/dialogs/qprogressdialog.cpp3
-rw-r--r--tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp45
2 files changed, 46 insertions, 2 deletions
diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp
index d160ab0ae1..35a75adea2 100644
--- a/src/widgets/dialogs/qprogressdialog.cpp
+++ b/src/widgets/dialogs/qprogressdialog.cpp
@@ -179,9 +179,8 @@ void QProgressDialogPrivate::layout()
void QProgressDialogPrivate::retranslateStrings()
{
- Q_Q(QProgressDialog);
if (useDefaultCancelText)
- q->setCancelButtonText(QProgressDialog::tr("Cancel"));
+ setCancelButtonText(QProgressDialog::tr("Cancel"));
}
void QProgressDialogPrivate::_q_disconnectOnClose()
diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
index 4ff158f632..86b9d7eee2 100644
--- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
+++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
@@ -50,6 +50,7 @@
#include <qlabel.h>
#include <qpointer.h>
#include <qthread.h>
+#include <qtranslator.h>
class tst_QProgressDialog : public QObject
{
@@ -63,6 +64,7 @@ private Q_SLOTS:
void task198202();
void QTBUG_31046();
void settingCustomWidgets();
+ void i18n();
};
void tst_QProgressDialog::cleanup()
@@ -234,5 +236,48 @@ void tst_QProgressDialog::settingCustomWidgets()
#endif
}
+class QTestTranslator : public QTranslator
+{
+ const QString m_str;
+public:
+ explicit QTestTranslator(QString str) : m_str(qMove(str)) {}
+
+ QString translate(const char *, const char *sourceText, const char *, int) const Q_DECL_OVERRIDE
+ { return m_str + sourceText + m_str; }
+
+ bool isEmpty() const Q_DECL_OVERRIDE { return false; }
+};
+
+template <typename Translator>
+class QTranslatorGuard {
+ Translator t;
+public:
+ template <typename Arg>
+ explicit QTranslatorGuard(Arg a) : t(qMove(a))
+ { qApp->installTranslator(&t); }
+ ~QTranslatorGuard()
+ { qApp->removeTranslator(&t); }
+};
+
+void tst_QProgressDialog::i18n()
+{
+ QProgressDialog dlg;
+ QPushButton *btn = dlg.findChild<QPushButton*>();
+ QVERIFY(btn);
+ const QString xxx = QStringLiteral("xxx");
+ {
+ QTranslatorGuard<QTestTranslator> guard(xxx);
+ {
+ QPushButton *btn = dlg.findChild<QPushButton*>();
+ QVERIFY(btn);
+ QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
+ QVERIFY(btn->text().startsWith(xxx));
+ }
+ }
+ QVERIFY(btn);
+ QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
+ QVERIFY(!btn->text().startsWith(xxx));
+}
+
QTEST_MAIN(tst_QProgressDialog)
#include "tst_qprogressdialog.moc"