QML Canvas causing crash

  • My application is essentially a dynamically created set of pages (similar to PageStack) with a ListView as one of the contained items. I've was using a Canvas as the ListView highlight component, which works great until a page is destroyed (or a previously painted page is repainted, not sure which). I'm not entirely sure what is going on here and could use some ideas. My ListView looks something like:

    ListView {
    highlight: Canvas {
    id: canvas
    antialiasing: true
    renderTarget: Canvas.Image

            onPaint: {
                var ctx = canvas.getContext('2d');
                ctx.fillStyle = "#555555"
                // Draw shapes
                ctx.clearRect(0,0,canvas.width, canvas.height);
                ctx.lineTo(0, canvas.height)
                ctx.lineTo(canvas.width*.93, canvas.height)
                ctx.lineTo(canvas.width, canvas.height/2)
                ctx.lineTo(canvas.width*.93, 0)
                ctx.lineTo(canvas.width*.93, 0)
                ctx.lineTo(0, 0)
        model: myModel
        delegate: Text {
            text: modelText


    I've noticed that I can comment out everything in the onPaint handler EXCEPT the getContext line, I still get the crash, so I'm assuming something about getContext is going wrong.

    Any help or ideas to debug this would be appreciated, thanks.

  • Can you paste a stacktrace of the crash? My guess is that in the crash case, the calling context is null because the component has been destroyed (and it presumably owns its own evaluation context).

    Either way, please file a bug report in JIRA and include all of the pertinent information as well as a minimal example which demonstrates the issue.


  • Here's a copy of the stack trace. I will try to create a simplified example and file a bug with it.

    0 QQuickFlickable::movementStarted Qt5Quickd 0x55c4619f
    1 QQuickFlickable::movementStarted Qt5Quickd 0x55b025a8
    2 QQuickFlickable::movementStarted Qt5Quickd 0x55b017f1
    3 QQuickFlickable::movementStarted Qt5Quickd 0x55afb979
    4 QQuickFlickable::movementStarted Qt5Quickd 0x55c2e7ae
    5 QQuickFlickable::movementStarted Qt5Quickd 0x55c2ed35
    6 QWidget::normalGeometry Qt5Widgetsd 0x5280291e
    7 QWidget::normalGeometry Qt5Widgetsd 0x5280035a
    8 QTimer::isSingleShot Qt5Cored 0x552a8264
    9 QTimer::isSingleShot Qt5Cored 0x552ad5e9
    10 QTimer::isSingleShot Qt5Cored 0x552a90e5
    11 QTimer::isSingleShot Qt5Cored 0x552a8d9d
    12 QCss::StyleSelector::selectorMatches Qt5Guid 0x533e84dd
    13 QWindowsGuiEventDispatcher::sendPostedEvents qwindowsguieventdispatcher.cpp 86 0x524cc014
    14 QTimer::isSingleShot Qt5Cored 0x553308d7
    15 InternalCallWinProc USER32 0x756662fa
    16 UserCallWinProcCheckWow USER32 0x75666d3a
    17 DispatchMessageWorker USER32 0x756677c4
    18 DispatchMessageW USER32 0x7566788a
    19 QTimer::isSingleShot Qt5Cored 0x553319c3
    20 QWindowsGuiEventDispatcher::processEvents qwindowsguieventdispatcher.cpp 78 0x524cbf7e
    21 QTimer::isSingleShot Qt5Cored 0x552a4ea1
    22 QTimer::isSingleShot Qt5Cored 0x552a4ffe
    23 QTimer::isSingleShot Qt5Cored 0x552a879d
    24 QCss::StyleSelector::selectorMatches Qt5Guid 0x533ff5e8
    25 QWidget::normalGeometry Qt5Widgetsd 0x52800009
    26 main main.cpp 78 0xe9ccfb
    27 WinMain qtmain_win.cpp 131 0xf4754a
    28 __tmainCRTStartup crtexe.c 547 0xf46ba0
    29 WinMainCRTStartup crtexe.c 371 0xf4692f
    30 BaseThreadInitThunk kernel32 0x766a33aa
    31 __RtlUserThreadStart ntdll32 0x77629ef2
    32 _RtlUserThreadStart ntdll32 0x77629ec5

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.