Answer the question
In order to leave comments, you need to log in
Exception when adding QGraphicsItem to stage?
ball class:
#endif // BALL_H
ball.cpp:
#include "ball.h"
ball::ball(int x, int y,int R)
{
this->x=x+10;
this->y=y;
this->R=R;
ballObj = new QGraphicsEllipseItem(x,y,R,R);
}
void ball::setPos(int newX, int newY)
{
this->x=newX;
this->y=newY;
}
void ball::setSpeed(int newSpeed)
{
this->speed=newSpeed;
}
QGraphicsEllipseItem* ball::getBall()
{
return this->ballObj;
}
QPoint ball::getPos()
{
return QPoint(this->x,this->y);
}
int ball::getSpeed()
{
return this->speed;
}
ballObj=new ball(0,this->height(),10);
gameBoard->scene()->addItem( ballObj->getBall());
Answer the question
In order to leave comments, you need to log in
In C++, all pointers must be checked for null before use. You obviously have some kind of null pointer.
This code still looks suspicious:
allObj=new ball(0,this->height(),10);
gameBoard->scene()->addItem( ballObj->getBall());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question