summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
authorOleksii Zbykovskyi <Oleksii.Zbykovskyi@qt.io>2025-07-28 13:47:21 +0200
committerOleksii Zbykovskyi <Oleksii.Zbykovskyi@qt.io>2025-07-29 15:20:01 +0200
commit4daf77582384764b78e5631e14e7a72a9c6288e3 (patch)
treeb907e88c94b96b37558efa2c2c69611e449fab15 /src/corelib/doc/snippets
parentc7a7783668f5ad92b30daf18ff52184a2aa5b4ca (diff)
Make last files in code folder compilable
Fixed small issues in each of the files and added to the build system. Task-number: QTBUG-137566 Change-Id: Iabe88b38c43f2db527027a0518840f16091898ad Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/CMakeLists.txt3
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp57
-rw-r--r--src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp16
-rw-r--r--src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp28
4 files changed, 72 insertions, 32 deletions
diff --git a/src/corelib/doc/snippets/code/CMakeLists.txt b/src/corelib/doc/snippets/code/CMakeLists.txt
index c657c8b966e..ee650c34a48 100644
--- a/src/corelib/doc/snippets/code/CMakeLists.txt
+++ b/src/corelib/doc/snippets/code/CMakeLists.txt
@@ -90,6 +90,9 @@ add_library(corelib_snippets_code OBJECT
src_corelib_tools_qshareddata.cpp
src_corelib_tools_qsharedpointer.cpp
src_corelib_tools_qsize.cpp
+ src_corelib_xml_qxmlstream.cpp
+ src_gui_itemviews_qidentityproxymodel.cpp
+ src_gui_itemviews_qitemselectionmodel.cpp
)
target_link_libraries(corelib_snippets_code PRIVATE
diff --git a/src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp b/src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp
index fe95b9939a0..9b002e1c904 100644
--- a/src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_xml_qxmlstream.cpp
@@ -1,30 +1,41 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
- QXmlStreamReader xml;
- ...
- while (!xml.atEnd()) {
- xml.readNext();
- ... // do processing
- }
- if (xml.hasError()) {
- ... // do error handling
- }
-//! [0]
+#include <QXmlStreamReader>
+#include <QXmlStreamWriter>
+void examples()
+{
+ {
+ //! [0]
+ QXmlStreamReader xml;
+ //...
+ while (!xml.atEnd()) {
+ xml.readNext();
+ //... do processing
+ }
+ if (xml.hasError()) {
+ //... do error handling
+ }
+ //! [0]
+ }
-//! [1]
- writeStartElement(qualifiedName);
- writeCharacters(text);
- writeEndElement();
-//! [1]
-
-
-//! [2]
- writeStartElement(namespaceUri, name);
- writeCharacters(text);
- writeEndElement();
-//! [2]
+ QXmlStreamWriter stream;
+ QString qualifiedName, namespaceUri, name, text;
+ {
+ //! [1]
+ stream.writeStartElement(qualifiedName);
+ stream.writeCharacters(text);
+ stream.writeEndElement();
+ //! [1]
+ }
+ {
+ //! [2]
+ stream.writeStartElement(namespaceUri, name);
+ stream.writeCharacters(text);
+ stream.writeEndElement();
+ //! [2]
+ }
+}
diff --git a/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
index e412670e2f7..b529f88a1f9 100644
--- a/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
+++ b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
@@ -1,6 +1,20 @@
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QIdentityProxyModel>
+#include <QDateTime>
+#include <QMap>
+#include <QModelIndex>
+#include <QVariant>
+
+class SourceClass
+{
+public:
+ enum Roles {
+ DateRole = 1
+ };
+};
+
//! [0]
class DateFormatProxyModel : public QIdentityProxyModel
{
@@ -11,7 +25,7 @@ class DateFormatProxyModel : public QIdentityProxyModel
m_formatString = formatString;
}
- QVariant data(const QModelIndex &index, int role) const override
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
{
if (role != Qt::DisplayRole)
return QIdentityProxyModel::data(index, role);
diff --git a/src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp b/src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp
index 0647f7f1c4e..0576c095421 100644
--- a/src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp
+++ b/src/corelib/doc/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp
@@ -1,13 +1,25 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
-QItemSelection *selection = new QItemSelection(topLeft, bottomRight);
-//! [0]
+#include <QItemSelection>
+#include <QModelIndex>
+void examples()
+{
+ QModelIndex topLeft;
+ QModelIndex bottomRight;
-//! [1]
-QItemSelection *selection = new QItemSelection();
-...
-selection->select(topLeft, bottomRight);
-//! [1]
+ {
+ //! [0]
+ QItemSelection *selection = new QItemSelection(topLeft, bottomRight);
+ //! [0]
+ }
+
+ {
+ //! [1]
+ QItemSelection *selection = new QItemSelection();
+ //...
+ selection->select(topLeft, bottomRight);
+ //! [1]
+ }
+}