summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets/code
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2021-05-28 17:43:37 +0200
committerKai Köhne <kai.koehne@qt.io>2021-06-09 16:22:08 +0200
commit704f0354998937363162fdb9ed6984a7339bc370 (patch)
treedcb12b137134d786edfdec8481b81d9d853e5e26 /src/corelib/doc/snippets/code
parent8a4e274dcf836f58c7417c11737bdded50a84dbd (diff)
Doc: Fix QVariant documentation
Update documentation to not reference API that is obsolete in Qt 6. Also fix documentation for changed behavior (isNull()), and fix snippets. Pick-to: 6.1 6.2 Change-Id: I526efeff63d907bbadd5e8a539ccf237cb992125 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets/code')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
index 1df3fa9edb..2dac3aefd7 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
@@ -53,7 +53,6 @@ QDataStream out(...);
QVariant v(123); // The variant now contains an int
int x = v.toInt(); // x = 123
out << v; // Writes a type tag and an int to out
-v = QVariant("hello"); // The variant now contains a QByteArray
v = QVariant(tr("hello")); // The variant now contains a QString
int y = v.toInt(); // y = 0 since v cannot be converted to an int
QString s = v.toString(); // s = tr("hello") (see QObject::tr())
@@ -64,16 +63,13 @@ in >> v; // Reads an Int variant
int z = v.toInt(); // z = 123
qDebug("Type is %s", // prints "Type is int"
v.typeName());
-v = v.toInt() + 100; // The variant now hold the value 223
-v = QVariant(QStringList());
+v = v.toInt() + 100; // The variant now holds the value 223
+v = QVariant(QStringList()); // The variant now holds a QStringList
//! [0]
-
//! [1]
-QVariant x, y(QString()), z(QString(""));
-x.convert(QMetaType::Int);
-// x.isNull() == true
-// y.isNull() == true, z.isNull() == false
+QVariant x; // x.isNull() == true
+QVariant y = QVariant::fromValue(nullptr); // y.isNull() == true
//! [1]
@@ -95,7 +91,7 @@ QVariant v;
v.setValue(5);
int i = v.toInt(); // i is now 5
-QString s = v.toString() // s is now "5"
+QString s = v.toString(); // s is now "5"
MyCustomStruct c;
v.setValue(c);