From 61f5cd478dfb3b16e56cf9a566c453ea0f97e5e9 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Fri, 27 Apr 2012 00:03:08 +0200 Subject: [PATCH] Qt 4.8 crash fix --- cockatrice/src/player.cpp | 6 ++---- cockatrice/src/playertarget.cpp | 11 +++++++++-- cockatrice/src/playertarget.h | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 09a3104e..58681cbf 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -1577,10 +1577,9 @@ void Player::delCounter(int counterId) AbstractCounter *c = counters.value(counterId, 0); if (!c) return; - if (c->getName() == "life") - playerTarget->delCounter(); - counters.remove(counterId); + c->delCounter(); + counters.remove(counterId); rearrangeCounters(); } @@ -1590,7 +1589,6 @@ void Player::clearCounters() while (counterIterator.hasNext()) counterIterator.next().value()->delCounter(); counters.clear(); - playerTarget->delCounter(); } ArrowItem *Player::addArrow(const ServerInfo_Arrow &arrow) diff --git a/cockatrice/src/playertarget.cpp b/cockatrice/src/playertarget.cpp index 358fc3ab..37d8e1be 100644 --- a/cockatrice/src/playertarget.cpp +++ b/cockatrice/src/playertarget.cpp @@ -56,6 +56,13 @@ PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem) fullPixmap = QPixmap(); } +PlayerTarget::~PlayerTarget() +{ + // Explicit deletion is necessary in spite of parent/child relationship + // as we need this object to be alive to receive the destroyed() signal. + delete playerCounter; +} + QRectF PlayerTarget::boundingRect() const { return QRectF(0, 0, 160, 64); @@ -136,12 +143,12 @@ AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name, playerCounter = new PlayerCounter(owner, _counterId, _name, _value, this); playerCounter->setPos(boundingRect().width() - playerCounter->boundingRect().width(), boundingRect().height() - playerCounter->boundingRect().height()); - connect(playerCounter, SIGNAL(destroyed()), this, SLOT(delCounter())); + connect(playerCounter, SIGNAL(destroyed()), this, SLOT(counterDeleted())); return playerCounter; } -void PlayerTarget::delCounter() +void PlayerTarget::counterDeleted() { playerCounter = 0; } diff --git a/cockatrice/src/playertarget.h b/cockatrice/src/playertarget.h index f8b6f2c4..398c67b0 100644 --- a/cockatrice/src/playertarget.h +++ b/cockatrice/src/playertarget.h @@ -22,12 +22,13 @@ private: QPixmap fullPixmap; PlayerCounter *playerCounter; public slots: - void delCounter(); + void counterDeleted(); public: enum { Type = typePlayerTarget }; int type() const { return Type; } PlayerTarget(Player *_player = 0, QGraphicsItem *parentItem = 0); + ~PlayerTarget(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);