[Interest] QML: onLoaded signal for QQuickWindow or QQmlApplicationEngine

Dmitry Volosnykh dmitry.volosnykh at gmail.com
Mon Jan 12 07:32:57 CET 2015


Try to do that inside Component.onCompleted handler. Note that, however, if you use images located remotely, then you should wait them to be loaded.

On Jan 12, 2015 9:17 AM, ruslan <ruslan at khvmntk.ru> wrote:
>
> 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.  
>
>
>
>
>


More information about the Interest mailing list