[Interest] QML: onLoaded signal for QQuickWindow or QQmlApplicationEngine
ruslan
ruslan at khvmntk.ru
Mon Jan 12 07:17:17 CET 2015
Hello all!
Is there any way to know when QML data was loaded into engine?
In my QML app I want to make a screenshot after all the source was loaded.
QQmlApplicationEngine engine;
engine.loadData(data);
QQuickWindow *rootObject = qobject_cast<QQuickWindow *>(p_engine.rootObjects().first());
QImage image = rootObject->grabWindow();
image.save("window.png","PNG",90);
where data is simple QML file:
import QtQuick 2.3
import QtQuick.Window 2.2
Window {
visible: true
width: 360
height: 360
Text {
anchors.centerIn: parent
text: "Hello, world!"
}
MouseArea {
anchors.fill: parent
//onClicked: someSingleton.makeScreenshot();
}
}
But image not saved just because it is empty. If I call QQuickWindow::grabWindow() from QML, for example, after clicking at MouseArea it works well.
So from this I conclude that when I call rootObject->grabWindow()it still not loaded completly yet.I've tried to call this function in this way:
connect(rootObject,&QQuickWindow::afterRendering,[=] () {
QImage image = rootObject->grabWindow();
image.save("window.png","PNG",90);
});
But the program just hungs up in this slot and no image was saved.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150112/2938c851/attachment.html>
More information about the Interest
mailing list