summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
index 2d7b9a9ac8..c73e782b76 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -440,6 +440,54 @@ QString global_greeting(int type)
//! [36]
+//! [qttrnnoop]
+static const char * const StatusClass::status_strings[] = {
+ QT_TR_N_NOOP("There are %n new message(s)"),
+ QT_TR_N_NOOP("There are %n total message(s)")
+};
+
+QString StatusClass::status(int type, int count)
+{
+ return tr(status_strings[type], nullptr, count);
+}
+//! [qttrnnoop]
+
+//! [qttranslatennoop]
+static const char * const greeting_strings[] = {
+ QT_TRANSLATE_N_NOOP("Welcome Msg", "Hello, you have %n message(s)"),
+ QT_TRANSLATE_N_NOOP("Welcome Msg", "Hi, you have %n message(s)")
+};
+
+QString global_greeting(int type, int msgcnt)
+{
+ return translate("Welcome Msg", greeting_strings[type], nullptr, msgcnt);
+}
+//! [qttranslatennoop]
+
+//! [qttranslatennoop3]
+static { const char * const source; const char * const comment; } status_strings[] = {
+ QT_TRANSLATE_N_NOOP3("Message Status", "Hello, you have %n message(s)",
+ "A login message status"),
+ QT_TRANSLATE_N_NOOP3("Message status", "You have %n new message(s)",
+ "A new message query status")
+};
+
+QString FriendlyConversation::greeting(int type, int count)
+{
+ return tr(status_strings[type].source,
+ status_strings[type].comment, count);
+}
+
+QString global_greeting(int type, int count)
+{
+ return qApp->translate("Message Status",
+ status_strings[type].source,
+ status_strings[type].comment,
+ count);
+}
+//! [qttranslatennoop3]
+
+
//! [qttrid]
//% "%n fooish bar(s) found.\n"
//% "Do you want to continue?"
@@ -677,3 +725,64 @@ bool readConfiguration(const QFile &file)
#include <QtGui>
#endif
//! [qt-version-check]
+
+//! [is-empty]
+ qgetenv(varName).isEmpty()
+//! [is-empty]
+
+//! [to-int]
+ qgetenv(varName).toInt(ok, 0)
+//! [to-int]
+
+//! [is-null]
+ !qgetenv(varName).isNull()
+//! [is-null]
+
+//! [as-const-0]
+ QString s = ...;
+ for (QChar ch : s) // detaches 's' (performs a deep-copy if 's' was shared)
+ process(ch);
+ for (QChar ch : qAsConst(s)) // ok, no detach attempt
+ process(ch);
+//! [as-const-0]
+
+//! [as-const-1]
+ const QString s = ...;
+ for (QChar ch : s) // ok, no detach attempt on const objects
+ process(ch);
+//! [as-const-1]
+
+//! [as-const-2]
+ for (QChar ch : funcReturningQString())
+ process(ch); // OK, the returned object is kept alive for the loop's duration
+//! [as-const-2]
+
+//! [as-const-3]
+ for (QChar ch : qAsConst(funcReturningQString()))
+ process(ch); // ERROR: ch is copied from deleted memory
+//! [as-const-3]
+
+//! [as-const-4]
+ for (QChar ch : qAsConst(funcReturningQString()))
+ process(ch); // ERROR: ch is copied from deleted memory
+//! [as-const-4]
+
+//! [qterminate]
+ try { expr; } catch(...) { qTerminate(); }
+//! [qterminate]
+
+//! [qdecloverride]
+ // generate error if this doesn't actually override anything:
+ virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
+//! [qdecloverride]
+
+//! [qdeclfinal-1]
+ // more-derived classes no longer permitted to override this:
+ virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_FINAL;
+//! [qdeclfinal-1]
+
+//! [qdeclfinal-2]
+ class QRect Q_DECL_FINAL { // cannot be derived from
+ // ...
+ };
+//! [qdeclfinal-2]