[Interest] QML: onLoaded signal for QQuickWindow or QQmlApplicationEngine

Dmitry Volosnykh dmitry.volosnykh at gmail.com
Mon Jan 12 09:21:48 CET 2015


Then you may try to expose some C++ class which has some slot (See
Integrating QML and C++
<http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html>). This slot can be
called from Component.onCompleted.

On Mon, Jan 12, 2015 at 9:32 AM, Dmitry Volosnykh <
dmitry.volosnykh at gmail.com> wrote:

> 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.
>
>
>
>
>
>
> 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.
> >
> >
> >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150112/c17fd754/attachment.html>


More information about the Interest mailing list