aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOleg Yadrov <oleg.yadrov@qt.io>2016-12-20 16:45:20 -0800
committerShawn Rutledge <shawn.rutledge@qt.io>2017-01-02 07:01:15 +0000
commitf70066e95e7e23562155686cb7d7874b2d5da5a1 (patch)
tree0e0741e13455291f4a433077ba6b0d7b0b56c0fb /tests/auto
parentbb123fa3a4b06dabb2a63304ee3d24f94d74c1f2 (diff)
Make it possible to call grabToImage() on Window.contentItem
Window.contentItem was not associated with any QQmlContext and QQmlEngine. A valid pointer to QQmlEngine is needed for callback function execution. Task-number: QTBUG-57175 Change-Id: Iab7730bfc8860521ff2e8c1631a11d0e1fe0cf94 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml15
-rw-r--r--tests/auto/quick/qquickwindow/qquickwindow.pro3
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp19
3 files changed, 36 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml b/tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml
new file mode 100644
index 0000000000..9086e0cc84
--- /dev/null
+++ b/tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+import QtQuick.Window 2.2 as Window
+
+Window.Window {
+ visible: true
+ width: 100
+ height: 100
+ property int success: 0
+
+ function grabContentItemToImage() {
+ contentItem.grabToImage(function (image) {
+ success = 1
+ })
+ }
+}
diff --git a/tests/auto/quick/qquickwindow/qquickwindow.pro b/tests/auto/quick/qquickwindow/qquickwindow.pro
index 05093ba8e0..b0a5f97a32 100644
--- a/tests/auto/quick/qquickwindow/qquickwindow.pro
+++ b/tests/auto/quick/qquickwindow/qquickwindow.pro
@@ -16,4 +16,5 @@ OTHER_FILES += \
data/AnimationsWhileHidden.qml \
data/Headless.qml \
data/showHideAnimate.qml \
- data/windoworder.qml
+ data/windoworder.qml \
+ data/grabContentItemToImage.qml
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index 300ca392f9..dd00154935 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -370,6 +370,8 @@ private slots:
void pointerEventTypeAndPointCount();
+ void grabContentItemToImage();
+
private:
QTouchDevice *touchDevice;
QTouchDevice *touchDeviceWithVelocity;
@@ -2554,6 +2556,23 @@ void tst_qquickwindow::pointerEventTypeAndPointCount()
QVERIFY(!pte.touchPointById(0));
}
+void tst_qquickwindow::grabContentItemToImage()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("grabContentItemToImage.qml"));
+
+ QObject *created = component.create();
+ QScopedPointer<QObject> cleanup(created);
+ QVERIFY(created);
+
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(created);
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QMetaObject::invokeMethod(window, "grabContentItemToImage");
+ QTRY_COMPARE(created->property("success").toInt(), 1);
+}
+
QTEST_MAIN(tst_qquickwindow)
#include "tst_qquickwindow.moc"