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

Alejandro Exojo suy at badopi.org
Sat Jan 31 16:11:01 CET 2015


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.

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.

-- 
Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
http://barnacity.net/ | http://disperso.net



More information about the Interest mailing list