diff options
Diffstat (limited to 'src/corelib/doc')
25 files changed, 457 insertions, 41 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp index 9a25918d47..7a70200cce 100644 --- a/src/corelib/doc/snippets/code/doc_src_properties.cpp +++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp @@ -40,8 +40,8 @@ //! [0] Q_PROPERTY(type name - READ getFunction - [WRITE setFunction] + (READ getFunction [WRITE setFunction] | + MEMBER memberName [(READ getFunction | WRITE setFunction)]) [RESET resetFunction] [NOTIFY notifySignal] [REVISION int] @@ -130,3 +130,20 @@ object->setProperty("priority", "VeryHigh"); //! [7] Q_CLASSINFO("Version", "3.0.0") //! [7] + +//! [8] + Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged) + Q_PROPERTY(qreal spacing MEMBER m_spacing NOTIFY spacingChanged) + Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged) + ... +signals: + void colorChanged(); + void spacingChanged(); + void textChanged(const QString &newText); + +private: + QColor m_color; + qreal m_spacing; + QString m_text; +//! [8] + 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 7d7d71ac50..59f05592be 100644 --- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp @@ -501,7 +501,7 @@ namespace QT_NAMESPACE { //! [43] class MyClass : public QObject { - + private: Q_DISABLE_COPY(MyClass) }; @@ -511,7 +511,7 @@ class MyClass : public QObject //! [44] class MyClass : public QObject { - + private: MyClass(const MyClass &); MyClass &operator=(const MyClass &); diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp index 2f81b15752..c448c75206 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp @@ -97,3 +97,37 @@ beginResetModel(); myData.clear(); endResetModel(); //! [11] + +//! [12] +class CustomDataProxy : public QSortFilterProxyModel +{ + Q_OBJECT +public: + CustomDataProxy(QObject *parent) + : QSortFilterProxyModel(parent) + { + } + + ... + + QVariant data(const QModelIndex &index, int role) + { + if (role != Qt::BackgroundRole) + return QSortFilterProxyModel::data(index, role); + + if (m_customData.contains(index.row())) + return m_customData.value(index.row()); + return QSortFilterProxyModel::data(index, role); + } + +private slots: + void resetInternalData() + { + m_customData.clear(); + } + +private: + QHash<int, QVariant> m_customData; +}; +//! [12] + diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp index cbb5a9db5d..c349a6dbba 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp @@ -57,7 +57,14 @@ foreach (const QString &path, app.libraryPaths()) //! [3] +// Called once QCoreApplication exists +static void preRoutineMyDebugTool() +{ + MyDebugTool* tool = new MyDebugTool(QCoreApplication::instance()); + QCoreApplication::instance()->installEventFilter(tool); +} +Q_COREAPP_STARTUP_FUNCTION(preRoutineMyDebugTool) //! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmath.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmath.cpp new file mode 100644 index 0000000000..71a2a09a7d --- /dev/null +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmath.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +float degrees = 180.0f +float radians = qDegreesToRadians(degrees) +//! [0] + + +//! [1] +double degrees = 180.0 +double radians = qDegreesToRadians(degrees) +//! [1] + + +//! [2] +float radians = float(M_PI) +float degrees = qRadiansToDegrees(radians) +//! [2] + + +//! [3] +double radians = M_PI +double degrees = qRadiansToDegrees(radians) +//! [3] + 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 bafd3f8eb8..68df53e0da 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -374,6 +374,7 @@ Q_PROPERTY(type name [WRITE setFunction] [RESET resetFunction] [NOTIFY notifySignal] + [REVISION int] [DESIGNABLE bool] [SCRIPTABLE bool] [STORED bool] diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp index de1a7cea19..92a6e77866 100644 --- a/src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qwaitcondition_unix.cpp @@ -84,6 +84,6 @@ forever { mutex.lock(); } keyPressed.wakeAll(); - mutex.unlock(); + mutex.unlock(); } //! [3] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp index 7e221cfaab..4f8c4c095e 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp @@ -405,7 +405,7 @@ QString tmp = "test"; QByteArray text = tmp.toLocal8Bit(); char *data = new char[text.size()] strcpy(data, text.data()); -delete [] data; +delete [] data; //! [46] //! [47] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp index a83fd9a71f..8c6751cbaa 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qpoint.cpp @@ -79,6 +79,13 @@ p *= 2.5; // p becomes (-3, 10) //! [5] +//! [16] +QPoint p( 3, 7); +QPoint q(-1, 4); +int lengthSquared = QPoint::dotProduct(p, q); // lengthSquared becomes 25 +//! [16] + + //! [6] QPoint p(-3, 10); p /= 2.5; // p becomes (-1, 4) @@ -147,3 +154,10 @@ p *= 2.5; // p becomes (-2.75, 10.25) QPointF p(-2.75, 10.25); p /= 2.5; // p becomes (-1.1, 4.1) //! [15] + + +//! [17] +QPointF p( 3.1, 7.1); +QPointF q(-1.0, 4.1); +int lengthSquared = QPointF::dotProduct(p, q); // lengthSquared becomes 26.01 +//! [17] diff --git a/src/corelib/doc/snippets/fileinfo/main.cpp b/src/corelib/doc/snippets/fileinfo/main.cpp index 57d7e32cb5..50acdb2550 100644 --- a/src/corelib/doc/snippets/fileinfo/main.cpp +++ b/src/corelib/doc/snippets/fileinfo/main.cpp @@ -54,12 +54,12 @@ int main(int argc, char *argv[]) QFileInfo fileInfo1("~/examples/191697/."); QFileInfo fileInfo2("~/examples/191697/.."); QFileInfo fileInfo3("~/examples/191697/main.cpp"); -//! [0] -//! [1] +//! [0] +//! [1] QFileInfo fileInfo4("."); QFileInfo fileInfo5(".."); QFileInfo fileInfo6("main.cpp"); -//! [1] +//! [1] qDebug() << fileInfo1.fileName(); qDebug() << fileInfo2.fileName(); diff --git a/src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp b/src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp new file mode 100644 index 0000000000..4441fbd9a1 --- /dev/null +++ b/src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + +//! [0] + QByteArray key = "key"; + QByteArray message = "The quick brown fox jumps over the lazy dog"; +//! [0] + +//! [1] + QMessageAuthenticationCode code(QCryptographicHash::Sha1); + code.setKey(key); + code.addData(message); + code.result().toHex(); // returns "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9" +//! [1] + +//! [2] + QMessageAuthenticationCode::hash(message, key, QCryptographicHash::Sha1).toHex(); +//! [2] +} diff --git a/src/corelib/doc/snippets/qmetaobject-revision/main.cpp b/src/corelib/doc/snippets/qmetaobject-revision/main.cpp new file mode 100644 index 0000000000..99a860b778 --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-revision/main.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QMetaObject> +#include <QMetaMethod> +#include <QMetaProperty> +#include <QDebug> +#include "window.h" + +void exposeMethod(const QMetaMethod &) +{ +} + +void exposeProperty(const QMetaProperty &) +{ +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); +//! [Window class using revision] + Window window; + int expectedRevision = 0; + const QMetaObject *windowMetaObject = window.metaObject(); + for (int i=0; i < windowMetaObject->methodCount(); i++) + if (windowMetaObject->method(i).revision() <= expectedRevision) + exposeMethod(windowMetaObject->method(i)); + for (int i=0; i < windowMetaObject->propertyCount(); i++) + if (windowMetaObject->property(i).revision() <= expectedRevision) + exposeProperty(windowMetaObject->property(i)); +//! [Window class using revision] + window.show(); + return app.exec(); +} diff --git a/src/corelib/doc/snippets/qmetaobject-revision/qmetaobject-revision.pro b/src/corelib/doc/snippets/qmetaobject-revision/qmetaobject-revision.pro new file mode 100644 index 0000000000..ec9d7db658 --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-revision/qmetaobject-revision.pro @@ -0,0 +1,4 @@ +QT += widgets +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp diff --git a/src/corelib/doc/snippets/qmetaobject-revision/window.cpp b/src/corelib/doc/snippets/qmetaobject-revision/window.cpp new file mode 100644 index 0000000000..0315f831be --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-revision/window.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "window.h" + +Window::Window() +{ +} + +int Window::normalProperty() +{ + return 0; +} + +int Window::newProperty() +{ + return 1; +} + +void Window::normalMethod() +{ + show(); +} + +void Window::newMethod() +{ + // Can be hidden from users expecting the initial API + show(); +} diff --git a/src/corelib/doc/snippets/qmetaobject-revision/window.h b/src/corelib/doc/snippets/qmetaobject-revision/window.h new file mode 100644 index 0000000000..6e56f3dfef --- /dev/null +++ b/src/corelib/doc/snippets/qmetaobject-revision/window.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +//! [Window class with revision] +class Window : public QWidget +{ + Q_OBJECT + Q_PROPERTY(int normalProperty READ normalProperty) + Q_PROPERTY(int newProperty READ newProperty REVISION 1) + +public: + Window(); + int normalProperty(); + int newProperty(); +public slots: + void normalMethod(); + Q_REVISION(1) void newMethod(); +}; +//! [Window class with revision] + +#endif diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index 6ee3088138..bf45a31c29 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -552,7 +552,7 @@ void Widget::replaceFunction() //! [86] QString equis = "xxxxxx"; equis.replace("xx", "x"); - // equis == "xxx" + // equis == "xxx" //! [86] //! [87] diff --git a/src/corelib/doc/snippets/sharedemployee/employee.h b/src/corelib/doc/snippets/sharedemployee/employee.h index 8025015a2e..2df1f71c51 100644 --- a/src/corelib/doc/snippets/sharedemployee/employee.h +++ b/src/corelib/doc/snippets/sharedemployee/employee.h @@ -69,11 +69,11 @@ class Employee setName(name); } //! [2] //! [7] - Employee(const Employee &other) - : d (other.d) - { - } -//! [7] + Employee(const Employee &other) + : d (other.d) + { + } +//! [7] //! [3] void setId(int id) { d->id = id; } //! [3] //! [4] diff --git a/src/corelib/doc/snippets/signalmapper/filereader.cpp b/src/corelib/doc/snippets/signalmapper/filereader.cpp index 42660b9551..cb83ea9362 100644 --- a/src/corelib/doc/snippets/signalmapper/filereader.cpp +++ b/src/corelib/doc/snippets/signalmapper/filereader.cpp @@ -73,7 +73,7 @@ FileReader::FileReader(QWidget *parent) /* //! [2] //slower due to signature normalization at runtime - + connect(signalMapper, SIGNAL(mapped(const QString &)), this, SLOT(readFile(const QString &))); //! [2] @@ -93,7 +93,7 @@ FileReader::FileReader(QWidget *parent) void FileReader::readFile(const QString &filename) { QFile file(filename); - + if (!file.open(QIODevice::ReadOnly)) { QMessageBox::information(this, tr("Unable to open file"), file.errorString()); diff --git a/src/corelib/doc/snippets/statemachine/eventtest.cpp b/src/corelib/doc/snippets/statemachine/eventtest.cpp index c83e92ab77..7454344680 100644 --- a/src/corelib/doc/snippets/statemachine/eventtest.cpp +++ b/src/corelib/doc/snippets/statemachine/eventtest.cpp @@ -55,11 +55,11 @@ protected: if (wrappedEvent->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(wrappedEvent); // Do your event test - } + } } return false; } -//![0] +//![0] void onTransition(QEvent *event) { diff --git a/src/corelib/doc/snippets/statemachine/main4.cpp b/src/corelib/doc/snippets/statemachine/main4.cpp index f1ecabd535..19b40a10b4 100644 --- a/src/corelib/doc/snippets/statemachine/main4.cpp +++ b/src/corelib/doc/snippets/statemachine/main4.cpp @@ -69,7 +69,7 @@ protected: StringEvent *se = static_cast<StringEvent*>(e); return (m_value == se->value); } - + virtual void onTransition(QEvent *) {} private: diff --git a/src/corelib/doc/snippets/streaming/main.cpp b/src/corelib/doc/snippets/streaming/main.cpp index 66808a5a6b..673df075ee 100644 --- a/src/corelib/doc/snippets/streaming/main.cpp +++ b/src/corelib/doc/snippets/streaming/main.cpp @@ -85,12 +85,12 @@ int main(int argc, char *argv[]) QByteArray byteArray; QDataStream stream(&byteArray, QIODevice::WriteOnly); stream << m; - + // display qDebug() << m.id << m.releaseDate << m.title; Movie m2; - + int id2; QString title2; QDate date2; diff --git a/src/corelib/doc/snippets/timers/timers.cpp b/src/corelib/doc/snippets/timers/timers.cpp index 4d74e7cc27..8257bf57a7 100644 --- a/src/corelib/doc/snippets/timers/timers.cpp +++ b/src/corelib/doc/snippets/timers/timers.cpp @@ -74,5 +74,5 @@ Foo::Foo() int main() { - + } diff --git a/src/corelib/doc/src/objectmodel/object.qdoc b/src/corelib/doc/src/objectmodel/object.qdoc index 281c1a30cb..89a781da39 100644 --- a/src/corelib/doc/src/objectmodel/object.qdoc +++ b/src/corelib/doc/src/objectmodel/object.qdoc @@ -66,16 +66,12 @@ by Qt's own \l{moc}{Meta-Object Compiler (moc)}. The meta-object system is a C++ extension that makes the language - better suited to true component GUI programming. Although - templates can be used to extend C++, the meta-object system - provides benefits using standard C++ that cannot be achieved with - templates; see \l{Why Doesn't Qt Use Templates for Signals and - Slots?} + better suited to true component GUI programming. \section1 Important Classes These classes form the basis of the Qt Object Model. - + \annotatedlist objectmodel \target Identity vs Value @@ -112,7 +108,7 @@ at runtime that are not declared in the C++ class. If we copy a Qt Object, should the copy include the properties that were added to the original? - + \endlist For these reasons, Qt Objects should be treated as identities, not diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc index 39f5e80eaa..d1690c5908 100644 --- a/src/corelib/doc/src/objectmodel/properties.qdoc +++ b/src/corelib/doc/src/objectmodel/properties.qdoc @@ -53,16 +53,22 @@ \snippet code/doc_src_properties.cpp 1 + Here is an example showing how to export member variables as Qt + properties using the \c MEMBER keyword. + Note that a \c NOTIFY signal must be specified to allow QML property bindings. + + \snippet code/doc_src_properties.cpp 8 + A property behaves like a class data member, but it has additional features accessible through the \l {Meta-Object System}. - \list + \list - \li A \c READ accessor function is required. It is for reading the - property value. Ideally, a const function is used for this purpose, - and it must return either the property's type or a pointer or - reference to that type. e.g., QWidget::focus is a read-only property - with \c READ function, QWidget::hasFocus(). + \li A \c READ accessor function is required if no \c MEMBER variable was + specified. It is for reading the property value. Ideally, a const function + is used for this purpose, and it must return either the property's type or a + pointer or reference to that type. e.g., QWidget::focus is a read-only + property with \c READ function, QWidget::hasFocus(). \li A \c WRITE accessor function is optional. It is for setting the property value. It must return void and must take exactly one @@ -71,6 +77,13 @@ QWidget::setEnabled(). Read-only properties do not need \c WRITE functions. e.g., QWidget::focus has no \c WRITE function. + \li A \c MEMBER variable association is required if no \c READ accessor + function is specified. This makes the given member variable + readable and writable without the need of creating \c READ and \c WRITE accessor + functions. It's still possible to use \c READ or \c WRITE accessor functions in + addition to \c MEMBER variable association (but not both), if you need to + control the variable access. + \li A \c RESET function is optional. It is for setting the property back to its context specific default value. e.g., QWidget::cursor has the typical \c READ and \c WRITE functions, QWidget::cursor() @@ -82,10 +95,14 @@ \li A \c NOTIFY signal is optional. If defined, it should specify one existing signal in that class that is emitted whenever the value of the property changes. + \c NOTIFY signals for \c MEMBER variables must take zero or one parameter, + which must be of the same type as the property. The parameter will take the + new value of the property. \li A \c REVISION number is optional. If included, it defines the property and its notifier signal to be used in a particular - revision of the API that is exposed to QML. + revision of the API (usually for exposure to QML). If not included, it + defaults to 0. \li The \c DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., @@ -114,7 +131,7 @@ gets and sets a widget's \c USER property. \li The presence of the \c CONSTANT attibute indicates that the property - value is constant. For a given object instance, the READ method of a + value is constant. For a given object instance, the READ method of a constant property must return the same value every time it is called. This constant value may be different for different instances of the object. A constant property cannot have a WRITE method or a NOTIFY signal. @@ -256,7 +273,7 @@ Q_DECLARE_METATYPE() macro so that their values can be stored in QVariant objects. This makes them suitable for use with both static properties declared using the Q_PROPERTY() macro in class - definitions and dynamic properties created at run-time. + definitions and dynamic properties created at run-time. \sa Q_DECLARE_METATYPE(), QMetaType, QVariant diff --git a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc index d897c4b9a7..4e285f2966 100644 --- a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc +++ b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc @@ -365,7 +365,7 @@ arguments can have default values. Consider QObject::destroyed(): \code - void destroyed(QObject* = 0); + void destroyed(QObject* = 0); \endcode When a QObject is deleted, it emits this QObject::destroyed() @@ -434,7 +434,7 @@ handle each signal differently. Suppose you have three push buttons that determine which file you - will open: "Tax File", "Accounts File", or "Report File". + will open: "Tax File", "Accounts File", or "Report File". In order to open the correct file, you use QSignalMapper::setMapping() to map all the clicked() signals to a QSignalMapper object. Then you connect |