PDA

View Full Version : QTimeLine



babu198649
30th January 2008, 13:31
hi
i have a QGraphicsItemAnimation object which after certain period requires change of one QTimeLine(which is already set) to another QTimeLine .
if i do this then the program crashes .
is there any way to change the animations timeline .

marcel
30th January 2008, 13:40
How exactly do you change the time line objects? Post some code, if possible.

babu198649
31st January 2008, 07:07
hi
i want to reset(not restarting ) the timeline.

this code crashes

ann = new QGraphicsItemAnimation;
timelineW = new QTimeLine(5000);
ann->setTimeLine(timelineW);

tim = new QTimeLine(1000);
ann->setTimeLine(tim); //resetting to new timeline

ann->setPosAt(0, QPointF(800, 10));
ann->setPosAt(1, QPointF(220, 10));
timelineW->start();

marcel
31st January 2008, 07:59
Beacause the item deletes the previous time line(if any) when you set a new one:


void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine)
{
if (d->timeLine == timeLine)
return;
if (d->timeLine)
delete d->timeLine;
if (!timeLine)
return;
d->timeLine = timeLine;
connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(setStep(qreal)));
}

Therefore timelineW is invalid after you set tim as the new time line.
You should call tim->start().

babu198649
31st January 2008, 08:46
thanks for pasting the perfect code .

marcel
31st January 2008, 08:52
If you want to reset the time line, why don't you use QTimeLine::setCurrentTime(0)?

babu198649
31st January 2008, 10:32
thanks.

If you want to reset the time line, why don't you use QTimeLine::setCurrentTime(0)?

the animation object should synchronize with the other items timer.