Hedge
Hedge

Reputation: 16748

How to fire off QML-animation from C++

I connected C++ and QML via a mediator-class and have everything working in both directions but this one puzzles me.

This is how I connect the mediator-class:

// Initialize Mediator between QML and C++
QmlCppMediator m_qmlCppMediator;
QDeclarativeContext *context = viewer.rootContext();
context->setContextProperty("cppInterface", &m_qmlCppMediator);

How to fire off an ordinary Property-Animation from within C++ ?

Upvotes: 0

Views: 1407

Answers (2)

Hedge
Hedge

Reputation: 16748

Ok I can answer this myself already.

I went for an approach described here http://qt-project.org/doc/qt-4.8/qdeclarativeanimation.html

I bind the “state” of the object which I try to animate to a Q_PROPERTY in the C++ interface. The different states are linked to transitions (in QML) which do the animate the object.

Upvotes: 1

RajaRaviVarma
RajaRaviVarma

Reputation: 2742

Rather an easy way would be to define a JavaScript function inside the QML file itself, lie this:

function startAnimation() {
 animationID.running = true;
}

Now call this code from C++, simple!

Upvotes: 0

Related Questions