Doc: Remove irrelevant sections from "Signals & Slots"

- This article is not the right place to describe the low-level
  mechanisms of moc and qmake, or to discuss QMetaObject features that
  are unrelated to signals and slots.
- Most users never need to run moc directly.
- The current content only mentions qmake for moc automation, but CMake,
  QBS, and the Visual Studio Add-In can also do that.

In light of the above 3 points, let's simply link to the "Meta-Object
System" article for those who are interested in the behind-the-scenes
details.

Most of the content deleted by this patch are already discussed in
detail in the articles "The Meta-Object System" and "Using the Meta-
Object Compiler (moc)" (the former links to the latter). The exception
is Snippet 5 -- this is deleted without replacement because
qobject_cast() is a much safer alternative to QMetaObject::inherits()
with static_cast(), so we should encourage the former.

Change-Id: I638c888cedfcdfb818747edeb806213ebd54dfb6
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
bb10
Sze Howe Koh 2014-08-31 21:42:48 +10:00
parent 4c08e3dfd5
commit f5d58c0442
2 changed files with 2 additions and 50 deletions

View File

@ -38,8 +38,6 @@
**
****************************************************************************/
#include <QAbstractButton>
#include "signalsandslots.h"
//! [0]
@ -66,19 +64,4 @@ int main()
//! [3] //! [4]
b.setValue(48); // a.value() == 12, b.value() == 48
//! [4]
QWidget *widget = reinterpret_cast<QWidget *>(new QObject(0));
//! [5]
if (widget->inherits("QAbstractButton")) {
QAbstractButton *button = static_cast<QAbstractButton *>(widget);
button->toggle();
//! [5] //! [6]
}
//! [6]
//! [7]
if (QAbstractButton *button = qobject_cast<QAbstractButton *>(widget))
button->toggle();
//! [7]
}

View File

@ -36,7 +36,8 @@
Signals and slots are used for communication between objects. The
signals and slots mechanism is a central feature of Qt and
probably the part that differs most from the features provided by
other frameworks.
other frameworks. Signals and slots are made possible by Qt's
\l{The Meta-Object System}{meta-object system}.
\tableofcontents
@ -182,17 +183,6 @@
\l{Using a Designer UI File in Your Application#Automatic Connections}
{automatic connections} feature.
\section1 Building the Example
The C++ preprocessor changes or removes the \c{signals},
\c{slots}, and \c{emit} keywords so that the compiler is
presented with standard C++.
By running the \l moc on class definitions that contain signals
or slots, a C++ source file is produced which should be compiled
and linked with the other object files for the application. If
you use \l qmake, the makefile rules to automatically invoke \c
moc will be added to your project's makefile.
\section1 Signals
@ -267,27 +257,6 @@
alongside a Qt-based application. To solve this problem, \c
#undef the offending preprocessor symbol.
\section1 Meta-Object Information
The meta-object compiler (\l moc) parses the class declaration in
a C++ file and generates C++ code that initializes the
meta-object. The meta-object contains the names of all the signal
and slot members, as well as pointers to these functions.
The meta-object contains additional information such as the
object's \l{QMetaObject::className()}{class name}. You can
also check if an object \l{QObject::inherits()}{inherits}
a specific class, for example:
\snippet signalsandslots/signalsandslots.cpp 5
\snippet signalsandslots/signalsandslots.cpp 6
The meta-object information is also used by qobject_cast<T>(), which
is similar to QObject::inherits() but is less error-prone:
\snippet signalsandslots/signalsandslots.cpp 7
See \l{Meta-Object System} for more information.
\section1 A Real Example