Fix potential crash in QStyleAnimation::updateCurrentTime()

A parentless/targetless QStyleAnimation calls updateCurrentTime() from
QAbstractAnimation constructor. Avoid the potential crash even if it's
not a valid use case for QStyleAnimation.

Change-Id: I9cd263d105c8ea4b5cbabac9a7680991745ccd95
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
J-P Nurmi 2012-10-16 17:39:52 +02:00 committed by The Qt Project
parent a98b943557
commit 9d86458d8c

View File

@ -83,15 +83,17 @@ bool QStyleAnimation::isUpdateNeeded() const
void QStyleAnimation::updateCurrentTime(int)
{
if (target()->isWidgetType()) {
QWidget *widget = static_cast<QWidget *>(target());
if (!widget->isVisible() || widget->window()->isMinimized())
stop();
}
if (QObject *tgt = target()) {
if (tgt->isWidgetType()) {
QWidget *widget = static_cast<QWidget *>(tgt);
if (!widget->isVisible() || widget->window()->isMinimized())
stop();
}
if (isUpdateNeeded()) {
QEvent event(QEvent::StyleAnimationUpdate);
QCoreApplication::sendEvent(target(), &event);
if (isUpdateNeeded()) {
QEvent event(QEvent::StyleAnimationUpdate);
QCoreApplication::sendEvent(tgt, &event);
}
}
}