[Interest] QML: onLoaded signal for QQuickWindow or QQmlApplicationEngine

Ruslan Moukhlynin ruslan at khvmntk.ru
Mon Jan 12 07:37:50 CET 2015


Yes, I know about Component.onCompleted but I need to do that in C++ 
part. Let's say I cannot modify QML data - all I need is to load it and 
make screenshot of loaded data.

Btw, Component.onCompleted also not works. I guess at this moment, whet 
this event triggers, some data isn't ready yet.


12.01.2015 16:32, Dmitry Volosnykh пишет:
> 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