From 5fa4e1d0981cbe52392f474d0297678915bc48f5 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 17 Nov 2014 12:36:30 +0100 Subject: [PATCH] TextEdit: fix construction time text cache QQuickTextEdit does not apply cached text to the underlying document until component construction is complete. However, if text() was called during the construction (eg. because of a binding), it would blindly overwrite the cached text with (still) empty document content. Task-number: QTBUG-41583 Change-Id: I6c5c1b6283d70d8a5ec2c8bd986095ee3c35a14c Reviewed-by: Pierre Rossi --- src/quick/items/qquicktextedit.cpp | 2 +- tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index b950f96..2771494 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -175,7 +175,7 @@ QQuickTextEdit::QQuickTextEdit(QQuickItem *parent) QString QQuickTextEdit::text() const { Q_D(const QQuickTextEdit); - if (!d->textCached) { + if (!d->textCached && isComponentComplete()) { QQuickTextEditPrivate *d = const_cast(d_func()); #ifndef QT_NO_TEXTHTMLPARSER if (d->richText) diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 4f10b4c..c61504e 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -201,6 +201,7 @@ private slots: void emptytags_QTBUG_22058(); void cursorRectangle_QTBUG_38947(); + void textCached_QTBUG_41583(); private: void simulateKeys(QWindow *window, const QList &keys); @@ -5302,6 +5303,17 @@ void tst_qquicktextedit::cursorRectangle_QTBUG_38947() QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, to); } +void tst_qquicktextedit::textCached_QTBUG_41583() +{ + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0\nTextEdit { property int margin: 10; text: \"TextEdit\"; textMargin: margin; property bool empty: !text; }", QUrl()); + QQuickTextEdit *textedit = qobject_cast(component.create()); + QVERIFY(textedit); + QCOMPARE(textedit->textMargin(), qreal(10.0)); + QCOMPARE(textedit->text(), QString("TextEdit")); + QVERIFY(!textedit->property("empty").toBool()); +} + QTEST_MAIN(tst_qquicktextedit) #include "tst_qquicktextedit.moc" -- 2.7.4