[Development] QML: Event which triggers after document was fully loaded
Ruslan Moukhlynin
ruslan at khvmntk.ru
Tue Jan 13 01:01:00 CET 2015
Hello all!
I'm working now at application which loads QML from a string and make
screenshot of a window.
And I'm surprised that there is no event which triggers when document
was completly loaded;
I talk about C++ part only.
The simple example:
QByteArray data("import QtQuick 2.3\n\
import QtQuick.Window 2.2\n\
\n\
Window {\n\
visible: true\n\
width: 360\n\
height: 360\n\
Text {\n\
anchors.centerIn: parent\n\
text: \"Hello, world!\"\n\
}\n\
}\n\");
QQmlApplicationEngine engine;
engine.loadData(data);
QQuickWindow *rootObject = qobject_cast<QQuickWindow
*>(engine.rootObjects().first());
connect(rootObject,&QQuickWindow::afterRendering,[=] () {
QImage image = rootObject->grabWindow();
image.save("window.png","PNG",90);
});
The execution hungs up on grabWindow(). All other events from
QQuickWindow also not works.
I was surpised again when tried to call grabWindow() from QML through
singleton:
Window {
....
Component.onCompleted: someSingleton.makeScreenshot();
....
}
It makes the image but text was not centered. It says that document was
not really completed yet! Or not?
So I came to conclusion that there is no way to know that a QML data was
loaded.
/P.S. Sorry for asking this question in development mail list but I've
asked it in all other places. It look that only Qt developers //can
clarify////this question./
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150113/eafe7f9f/attachment.html>
More information about the Development
mailing list