-1
私はこのようなメインコンストラクターにqtimerをセットアップしました。Qtクリエーターでqtimerを停止する
Ball::Ball(QGraphicsItem *parent): QGraphicsRectItem(parent), QObject(){
// draw rect
setRect(0,0,50,50);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::red);
setBrush(brush);
// move up right initially
xVelocity = 0;
yVelocity = -5;
QTimer* timer = new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(move()));
timer->start(15);
}
タイマのmove()fuctionは定期的に実行されます。上記のreverseVelocityIfOutOfBounds()で、
void Ball::move(){
reverseVelocityIfOutOfBounds();
handlePaddleCollision();
handleBlockCollision();
moveBy(xVelocity,yVelocity);
}
このような条件があります。
// bottom edge - NONE (can fall through bottom)
if (mapToScene(rect().topRight()).y() >= screenH){
これを実行するとQtimerを停止します。私はできる限りすべてを適用した。プログラムが予期せず終了することがあります。どのような助けが非常にappriciatedされますようにしてください。
この質問は[最小限の完全で検証可能な例](https://stackoverflow.com/help/mcve)がなければ答えることができません。 – MrEricSir