diff options
Diffstat (limited to 'src/corelib/doc')
9 files changed, 106 insertions, 34 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp b/src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp index e2cf761ff8..eacc94b19f 100644 --- a/src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_codecs_qtextcodec.cpp @@ -63,13 +63,3 @@ while (new_data_available()) { } delete decoder; //! [2] - - -//! [3] -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - QTextCodec::setCodecForTr(QTextCodec::codecForName("eucKR")); - ... -} -//! [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 b0048014a4..8846437b7c 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -418,17 +418,17 @@ QString example = tr("Example"); //! [40] //! [41] -QPushButton *button = parentWidget->findChild<QPushButton *>("button1", Qt::FindDirectChildOnly); +QPushButton *button = parentWidget->findChild<QPushButton *>("button1", Qt::FindDirectChildrenOnly); //! [41] //! [42] -QListWidget *list = parentWidget->findChild<QListWidget *>(QString(), Qt::FindDirectChildOnly); +QListWidget *list = parentWidget->findChild<QListWidget *>(QString(), Qt::FindDirectChildrenOnly); //! [42] //! [43] -QList<QPushButton *> childButtons = parentWidget.findChildren<QPushButton *>(QString(), Qt::FindDirectChildOnly); +QList<QPushButton *> childButtons = parentWidget.findChildren<QPushButton *>(QString(), Qt::FindDirectChildrenOnly); //! [43] //! [44] @@ -486,6 +486,33 @@ QObject::connect(socket, &QTcpSocket::connected, this, [=] () { }, Qt::AutoConnection); //! [51] +//! [52] +class MyClass : public QWidget +{ + Q_OBJECT + +public: + MyClass(QWidget *parent = 0); + ~MyClass(); + + bool event(QEvent* ev) + { + if (ev->type() == QEvent::PolishRequest) { + // overwrite handling of PolishRequest if any + doThings(); + return true; + } else if (ev->type() == QEvent::Show) { + // complement handling of Show if any + doThings2(); + QWidget::event(ev); + return true; + } + // Make sure the rest of events are handled + return QWidget::event(ev); + } +}; +//! [52] + //! [meta data] //: This is a comment for the translator. //= qtn_foo_bar diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp index 43d64fc08e..0ac7cb5769 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp @@ -298,6 +298,25 @@ while (i != hash.end() && i.key() == "plenty") { } //! [26] +//! [27] +for (QHash<int, QString>::const_iterator it = hash.cbegin(), end = hash.cend(); it != end; ++it) { + cout << "The key: " << it.key() << endl + cout << "The value: " << it.value() << endl; + cout << "Also the value: " << (*it) << endl; +} +//! [27] + +//! [28] +// Inefficient, keys() is expensive +QList<int> keys = hash.keys(); +int numPrimes = std::count_if(keys.cbegin(), keys.cend(), isPrimeNumber); +qDeleteAll(hash2.keys()); + +// Efficient, no memory allocation needed +int numPrimes = std::count_if(hash.keyBegin(), hash.keyEnd(), isPrimeNumber); +qDeleteAll(hash2.keyBegin(), hash2.keyEnd()); +//! [28] + //! [qhashbits] inline uint qHash(const std::vector<int> &key, uint seed = 0) { diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp index 7580b6bbaf..29e53fc700 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp @@ -311,3 +311,22 @@ while (i != map.end() && i.key() == "plenty") { ++i; } //! [27] + +//! [keyiterator1] +for (QMap<int, QString>::const_iterator it = map.cbegin(), end = map.cend(); it != end; ++it) { + cout << "The key: " << it.key() << endl + cout << "The value: " << it.value() << endl; + cout << "Also the value: " << (*it) << endl; +} +//! [keyiterator1] + +//! [keyiterator2] +// Inefficient, keys() is expensive +QList<int> keys = map.keys(); +int numPrimes = std::count_if(map.cbegin(), map.cend(), isPrimeNumber); +qDeleteAll(map2.keys()); + +// Efficient, no memory allocation needed +int numPrimes = std::count_if(map.keyBegin(), map.keyEnd(), isPrimeNumber); +qDeleteAll(map2.keyBegin(), map2.keyEnd()); +//! [keyiterator2] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp index 77b34c95fc..5def361b83 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp @@ -84,14 +84,27 @@ for (int i = 0; i < 10; ++i) //! [7] -QVector<QString> vector(0); +QVector<QString> vector; vector.append("one"); vector.append("two"); -vector.append("three"); +QString three = "three"; +vector.append(three); // vector: ["one", "two", "three"] +// three: "three" //! [7] +//! [move-append] +QVector<QString> vector; +vector.append("one"); +vector.append("two"); +QString three = "three"; +vector.append(std::move(three)); +// vector: ["one", "two", "three"] +// three: "" +//! [move-append] + + //! [8] QVector<QString> vector; vector.prepend("one"); diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc index f8d0d3eb05..0ae3817ac7 100644 --- a/src/corelib/doc/src/containers.qdoc +++ b/src/corelib/doc/src/containers.qdoc @@ -169,8 +169,8 @@ convenience, the containers are forward declared in \c <QtContainerFwd>. - \keyword assignable data type - \keyword assignable data types + \target assignable data type + \target assignable data types The values stored in the various containers can be of any \e{assignable data type}. To qualify, a type must provide a @@ -220,7 +220,7 @@ \codeline \snippet streaming/main.cpp 2 - \keyword default-constructed value + \target default-constructed value The documentation of certain container class functions refer to \e{default-constructed values}; for example, QVector @@ -546,7 +546,7 @@ The above example only shows a problem with QVector, but the problem exists for all the implicitly shared Qt containers. - \keyword foreach + \target foreach \section1 The foreach Keyword If you just want to iterate over all the items in a container @@ -655,11 +655,11 @@ To describe algorithmic complexity, we use the following terminology, based on the "big Oh" notation: - \keyword constant time - \keyword logarithmic time - \keyword linear time - \keyword linear-logarithmic time - \keyword quadratic time + \target constant time + \target logarithmic time + \target linear time + \target linear-logarithmic time + \target quadratic time \list \li \b{Constant time:} O(1). A function is said to run in constant diff --git a/src/corelib/doc/src/external-resources.qdoc b/src/corelib/doc/src/external-resources.qdoc index ec4715c933..d612ce8280 100644 --- a/src/corelib/doc/src/external-resources.qdoc +++ b/src/corelib/doc/src/external-resources.qdoc @@ -65,4 +65,13 @@ \externalpage http://doc-snapshot.qt-project.org/qt5-5.4/designer-widget-mode.html#the-property-editor \title Qt Designer's Widget Editing Mode#The Property Editor */ + +/*! + \externalpage http://marcmutz.wordpress.com/effective-qt/containers/#containers-qlist + \title Pros and Cons of Using QList +*/ + +/*! + \externalpage http://marcmutz.wordpress.com/effective-qt/containers/ + \title Understand the Qt Containers */ diff --git a/src/corelib/doc/src/implicit-sharing.qdoc b/src/corelib/doc/src/implicit-sharing.qdoc index 57ebf55c17..d5a8e327ac 100644 --- a/src/corelib/doc/src/implicit-sharing.qdoc +++ b/src/corelib/doc/src/implicit-sharing.qdoc @@ -71,8 +71,8 @@ data. The shared data is deleted when the reference count becomes zero. - \keyword deep copy - \keyword shallow copy + \target deep copy + \target shallow copy When dealing with shared objects, there are two ways of copying an object. We usually speak about \e deep and \e shallow copies. A deep @@ -142,6 +142,6 @@ (QMap, QVector, etc.) while you use \l{STL-style iterators}{STL-style iterator}. See \l{Implicit sharing iterator problem}. - \keyword implicitly shared classes + \target implicitly shared classes \annotatedlist shared */ diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc index abb0720fe9..55622dd56b 100644 --- a/src/corelib/doc/src/objectmodel/properties.qdoc +++ b/src/corelib/doc/src/objectmodel/properties.qdoc @@ -160,13 +160,8 @@ Because QDate is user-defined, you must include the \c{<QDate>} header file with the property declaration. - For QMap, QList, and QValueList properties, the property value is - a QVariant whose value is the entire list or map. Note that the - Q_PROPERTY string cannot contain commas, because commas separate - macro arguments. Therefore, you must use \c QMap as the property - type instead of \c QMap<QString,QVariant>. For consistency, also - use \c QList and \c QValueList instead of \c QList<QVariant> and - \c QValueList<QVariant>. + For historical reasons, \a QMap and \a QList as property types + are synonym of \a QVariantMap and \a QVariantList. \section1 Reading and Writing Properties with the Meta-Object System |