[Interest] [QML] [solved] Different behaviour between QML Scene and QQmlApplicationEngine when using getContext("2d")

Christoph Petzold christoph.petzold at hasomed.de
Mon Feb 2 09:25:02 CET 2015


Hi Alejandro Exojo,

> -----Ursprüngliche Nachricht-----
> Von: interest-bounces+christoph.petzold=hasomed.de at qt-project.org
> [mailto:interest-bounces+christoph.petzold=hasomed.de at qt-project.org] 
> Im Auftrag von Alejandro Exojo
> Gesendet: Samstag, 31. Januar 2015 16:11
> An: interest at qt-project.org
> Betreff: Re: [Interest] [QML] Different behaviour between QML Scene 
> and QQmlApplicationEngine when using getContext("2d")
> 
> El Thursday 29 January 2015, Christoph Petzold escribió:
> > qrc:/NotWorkingRectangle.qml:7:5: QML Canvas: Unable to use
> > getContext() at this time, please wait for available: true
> (...)
> 
> > NotWorkingRectangle.qml:
> > -----------------------------------
> > import QtQuick 2.3
> > import QtQuick.Controls 1.2
> > Rectangle {
> >     anchors.fill: parent
> >     Canvas {
> >         property var ctx: getContext("2d")
> (...)
> 
> > In my real world component i have lots of painting functions and i 
> > do not want to pass the ctx element every time i want to use it. I 
> > also do not want to call getContext("2d") locally. I know it returns 
> > the same Object every next call but it is just code i would like to spare.
> 
> There are some things that I might try:
> 
> Does it change if you set the property in Component.onCompleted? Or 
> better yet, onAvailableChanged? After all is what the warning suggests.

Yes, both solutions are working fine for me.

> 
> Note that your cpp file uses QQmlApplicationEngine, while qmlscene 
> uses a QQuickView IIRC. It might be that some initialization is done 
> earlier with the latter.
> 
> Also, note that the canvas element already has a "context" property, 
> so you should have access to it anyway. I don't understand why you 
> want the custom "ctx" one.

This is a really good point. I just did not know this. 

Thank you very much for you're help!

> 
> --
> Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
> http://barnacity.net/ | http://disperso.net 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> 
> !DSPAM:1879,54ccf0a0267601779215299!
>




More information about the Interest mailing list