summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-05-14 12:59:42 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-05-15 18:46:39 +0200
commit794150e5bda0c203a5373c3fa2f9785f9941f6dd (patch)
tree2588b9ad3e3034ac9ee8a03a75d26c23223402cd
parent45cf8da63c419c27e7476f0a929e9d8ba664bfd3 (diff)
QMetaType: Support char16_t and char32_t
Change-Id: Ieec6d4bc64967d875ea12b31638aab05bc682ea3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/kernel/qmetatype.h5
-rw-r--r--src/corelib/serialization/qdatastream.cpp49
-rw-r--r--src/corelib/serialization/qdatastream.h5
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h6
4 files changed, 64 insertions, 1 deletions
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 96133c13c5..05fe4450df 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -85,6 +85,8 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId();
F(Long, 32, long) \
F(Short, 33, short) \
F(Char, 34, char) \
+ F(Char16, 56, char16_t) \
+ F(Char32, 57, char32_t) \
F(ULong, 35, ulong) \
F(UShort, 36, ushort) \
F(UChar, 37, uchar) \
@@ -451,7 +453,7 @@ public:
QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)
FirstCoreType = Bool,
- LastCoreType = QCborMap,
+ LastCoreType = Char32,
FirstGuiType = QFont,
LastGuiType = QColorSpace,
FirstWidgetsType = QSizePolicy,
@@ -482,6 +484,7 @@ public:
Nullptr = 51,
QVariantMap = 8, QVariantList = 9, QVariantHash = 28,
QCborSimpleType = 52, QCborValue = 53, QCborArray = 54, QCborMap = 55,
+ Char16 = 56, Char32 = 57,
// Gui types
QFont = 64, QPixmap = 65, QBrush = 66, QColor = 67, QPalette = 68,
diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp
index df286085bc..3026e554bf 100644
--- a/src/corelib/serialization/qdatastream.cpp
+++ b/src/corelib/serialization/qdatastream.cpp
@@ -1025,6 +1025,31 @@ QDataStream &QDataStream::operator>>(char *&s)
return readBytes(s, len);
}
+/*!
+ \overload
+
+ Reads a char from the stream into char \a chr.
+*/
+QDataStream &QDataStream::operator>>(char16_t &c)
+{
+ quint16 u;
+ *this >> u;
+ c = char16_t(u);
+ return *this;
+}
+
+/*!
+ \overload
+
+ Reads a char from the stream into char \a chr.
+*/
+QDataStream &QDataStream::operator>>(char32_t &c)
+{
+ quint32 u;
+ *this >> u;
+ c = char32_t(u);
+ return *this;
+}
/*!
Reads the buffer \a s from the stream and returns a reference to
@@ -1338,6 +1363,30 @@ QDataStream &QDataStream::operator<<(const char *s)
}
/*!
+ \overload
+ \since 6.0
+
+ Writes a character, \a c, to the stream. Returns a reference to
+ the stream
+*/
+QDataStream &QDataStream::operator<<(char16_t c)
+{
+ return *this << qint16(c);
+}
+
+/*!
+ \overload
+ \since 6.0
+
+ Writes a character, \a c, to the stream. Returns a reference to
+ the stream
+*/
+QDataStream &QDataStream::operator<<(char32_t c)
+{
+ return *this << qint32(c);
+}
+
+/*!
Writes the length specifier \a len and the buffer \a s to the
stream and returns a reference to the stream.
diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h
index c7b0008039..4568ba3a84 100644
--- a/src/corelib/serialization/qdatastream.h
+++ b/src/corelib/serialization/qdatastream.h
@@ -163,6 +163,8 @@ public:
QDataStream &operator>>(float &f);
QDataStream &operator>>(double &f);
QDataStream &operator>>(char *&str);
+ QDataStream &operator>>(char16_t &c);
+ QDataStream &operator>>(char32_t &c);
QDataStream &operator<<(qint8 i);
QDataStream &operator<<(quint8 i);
@@ -178,6 +180,9 @@ public:
QDataStream &operator<<(float f);
QDataStream &operator<<(double f);
QDataStream &operator<<(const char *str);
+ QDataStream &operator<<(char16_t c);
+ QDataStream &operator<<(char32_t c);
+
QDataStream &readBytes(char *&, uint &len);
int readRawData(char *, int len);
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h
index bf01fdcfcd..3f00db5519 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h
@@ -136,6 +136,12 @@ template<> struct TestValueFactory<QMetaType::Short> {
template<> struct TestValueFactory<QMetaType::Char> {
static char *create() { return new char('c'); }
};
+template<> struct TestValueFactory<QMetaType::Char16> {
+ static char16_t *create() { return new char16_t('c'); }
+};
+template<> struct TestValueFactory<QMetaType::Char32> {
+ static char32_t *create() { return new char32_t('c'); }
+};
template<> struct TestValueFactory<QMetaType::ULong> {
static ulong *create() { return new ulong(ULONG_MAX); }
};