-1

I wrote a c++ QQuickItem component for drawing curve, but for updating the curve, i have to call update method by a timer.

example of what i am doing:

Item {
    Curve {
        id: curve
        height: 100
        width: 600
    }

Timer {
    id: timer
    interval:20
    repeat: true
    running: true
    onTriggered: {
        curve.update()
    }
 }
}

Is there any way to call it from C++?

Mohsen Zahraee
  • 3,309
  • 5
  • 31
  • 45

1 Answers1

0

The function you seek is:

void QQuickWindow::update()

Schedules the window to render another frame.

Calling QQuickWindow::update() differs from QQuickItem::update() in that it always triggers a repaint, regardless of changes in the underlying scene graph or not.

You can get access to the underlying window from any QQuickItem, for example someItem->window()->update(), or you can pass the Window or ApplicationWindow directly.

You will have to implement a basic QObject derived accessor object so you can invoke the C++ function from QML, passing it a QML object as a parameter, either a window or item. Then create an instance in main.cpp, expose it as a context property, then from QML you can simply onTriggered: Accessor.requestUpdate(someItem/someWindow)

dtech
  • 47,916
  • 17
  • 112
  • 190