summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-10-25 07:21:05 +0200
committerLiang Qi <liang.qi@qt.io>2018-10-25 07:21:53 +0200
commite28e91ae99b8c3859899e04cc9370534c7c7b86d (patch)
treecca81b1e745be4f25aab78e8e917c2324594e539 /src/corelib/global/qglobal.cpp
parent5ea233ca6782eb27adf596515cb66ef3dadc1d5e (diff)
parentebfad73b4e44fe6db8059200da105b4b87888718 (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts: src/corelib/animation/qpropertyanimation.cpp src/gui/image/qicon.cpp tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp Change-Id: I3698172b7b44ebb487cb38f50fd2c4a9f8a35b21
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp61
1 files changed, 12 insertions, 49 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 0fba9b309b..14fb4e77da 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -3413,9 +3413,7 @@ QString qEnvironmentVariable(const char *varName)
Returns whether the environment variable \a varName is empty.
Equivalent to
- \code
- qgetenv(varName).isEmpty()
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp is-empty
except that it's potentially much faster, and can't throw exceptions.
\sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsSet()
@@ -3445,9 +3443,7 @@ bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT
on the success of the conversion.
Equivalent to
- \code
- qgetenv(varName).toInt(ok, 0)
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp to-int
except that it's much faster, and can't throw exceptions.
\note there's a limit on the length of the value, which is sufficient for
@@ -3521,9 +3517,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT
Returns whether the environment variable \a varName is set.
Equivalent to
- \code
- !qgetenv(varName).isNull()
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp is-null
except that it's potentially much faster, and can't throw exceptions.
\sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsEmpty()
@@ -3699,37 +3693,21 @@ bool qunsetenv(const char *varName)
Its main use in Qt is to prevent implicitly-shared Qt containers
from detaching:
- \code
- 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);
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp as-const-0
Of course, in this case, you could (and probably should) have declared
\c s as \c const in the first place:
- \code
- const QString s = ...;
- for (QChar ch : s) // ok, no detach attempt on const objects
- process(ch);
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp as-const-1
but often that is not easily possible.
It is important to note that qAsConst() does not copy its argument,
it just performs a \c{const_cast<const T&>(t)}. This is also the reason
why it is designed to fail for rvalues: The returned reference would go
stale too soon. So while this works (but detaches the returned object):
- \code
- for (QChar ch : funcReturningQString())
- process(ch); // OK, the returned object is kept alive for the loop's duration
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp as-const-2
this would not:
- \code
- for (QChar ch : qAsConst(funcReturningQString()))
- process(ch); // ERROR: ch is copied from deleted memory
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp as-const-3
To prevent this construct from compiling (and failing at runtime), qAsConst() has
a second, deleted, overload which binds to rvalues.
@@ -3742,10 +3720,7 @@ bool qunsetenv(const char *varName)
\overload
This overload is deleted to prevent a dangling reference in code like
- \code
- for (QChar ch : qAsConst(funcReturningQString()))
- process(ch); // ERROR: ch is copied from deleted memory
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp as-const-4
*/
/*!
@@ -4679,9 +4654,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
purpose. It either expands to \c expr (if Qt is compiled without
exception support or the compiler supports C++11 noexcept
semantics) or to
- \code
- try { expr; } catch(...) { qTerminate(); }
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp qterminate
otherwise.
Since this macro expands to just \c expr if the compiler supports
@@ -4751,10 +4724,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
The macro goes at the end of the function, usually after the
\c{const}, if any:
- \code
- // generate error if this doesn't actually override anything:
- virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp qdecloverride
\sa Q_DECL_FINAL
*/
@@ -4776,18 +4746,11 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
The macro goes at the end of the function, usually after the
\c{const}, if any:
- \code
- // more-derived classes no longer permitted to override this:
- virtual void MyWidget::paintEvent(QPaintEvent*) Q_DECL_FINAL;
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-1
For classes, it goes in front of the \c{:} in the class
definition, if any:
- \code
- class QRect Q_DECL_FINAL { // cannot be derived from
- // ...
- };
- \endcode
+ \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-2
\sa Q_DECL_OVERRIDE
*/