summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qstring.h2
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp9
2 files changed, 10 insertions, 1 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 129a53e227..285369a736 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -685,7 +685,7 @@ private:
typedef QLatin1String QLatin1Literal;
-inline QString::QString(const QLatin1String &aLatin1) : d(fromLatin1_helper(aLatin1.latin1()))
+inline QString::QString(const QLatin1String &aLatin1) : d(fromLatin1_helper(aLatin1.latin1(), aLatin1.size()))
{ }
inline int QString::length() const
{ return d->size; }
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index f3ff6e08e2..781377f574 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -223,6 +223,7 @@ private slots:
void operatorGreaterWithQLatin1String();
void compareQLatin1Strings();
+ void fromQLatin1StringWithLength();
};
typedef QList<int> IntList;
@@ -5277,6 +5278,14 @@ void tst_QString::compareQLatin1Strings()
QVERIFY(!(subab >= subabc));
}
+void tst_QString::fromQLatin1StringWithLength()
+{
+ QLatin1String latin1foo("foobar", 3);
+ QString foo(latin1foo);
+ QCOMPARE(foo.size(), latin1foo.size());
+ QCOMPARE(foo, QString::fromLatin1("foo"));
+}
+
QTEST_APPLESS_MAIN(tst_QString)
#include "tst_qstring.moc"