summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2013-02-01 14:39:23 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-02 10:03:04 +0100
commitc5c584c116798c495d78a4d89c568a77bc065010 (patch)
tree60d8d1bf1b617f0e2ae7c0865002976e14019052 /src/corelib/doc/snippets
parent3ba61d9baa569ea69e41a943981680c09c521ff7 (diff)
Optimize code sample of QObject::isSignalConnected
Since isSignalConnected is meant to be used in performance critical code, and that QMetaMethod::fromSignal is relatively slow, it is better to have it a a static variable in the code sample, as a good recommendation on how to use it. Since QMetaMethod::fromSignal should not change during the life of the program, it should be safe. Also, if different threads run at the same time, both should lead to the same result. Change-Id: Ib6113d11ca93f216bc3a92aea4eaa4da6a4151ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp
index 932a006436..bafd3f8eb8 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp
@@ -480,7 +480,8 @@ QObject::disconnect(lineEdit, &QLineEdit::textChanged,
//! [48]
//! [49]
-if (isSignalConnected(QMetaMethod::fromSignal(&MyObject::valueChanged))) {
+static const QMetaMethod valueChangedSignal = QMetaMethod::fromSignal(&MyObject::valueChanged);
+if (isSignalConnected(valueChangedSignal)) {
QByteArray data;
data = get_the_value(); // expensive operation
emit valueChanged(data);