need help SigSegv fault with normal + calculation
-
hi there;
i need help to figure out my problem
everytime i try to debugg it there is a sigsegv fault
here are my classes:#include "munition.h"
#include "gegner.h"
#include "mainwindow.h"
#include "game.h"
#include "punkte.h"
#include "QTimer"
#include "QDebug"
#include "QGraphicsScene"
extern MainWindow * mainwindow;
Munition::Munition()
{
//rect zeichnen
setRect(0,0,2,10);//connect QTimer *timer =new QTimer(); connect(timer,SIGNAL(timeout()),this,SLOT(move())); timer->start(40);
}
void Munition::move()
{//Punkte * punkte; //muni kollidiert QList<QGraphicsItem *> colliding_items=collidingItems(); for(int i=0,n=colliding_items.size();i<n;i++) { if(typeid (*(colliding_items[i]))==typeid(Gegner)) { punkten->punkten();//here i go to the other class //mainwindow->punkte->punkten(); //both removen scene()->removeItem(colliding_items[i]); scene()->removeItem(this); //delete both delete colliding_items[i]; delete this; return; } } //move muni up setPos(x(),y()-10); if(pos().y()<0) { scene()->removeItem(this); delete this; }
}
#include "punkte.h"
#include "QFont"
using namespace std;
Punkte::Punkte(QGraphicsItem *parent): QGraphicsTextItem(parent)
{
punkte=0;
plus=250;setPlainText(QString("punkte:")+QString::number(punkte)); setDefaultTextColor(Qt::red); setFont(QFont("times",16));
}
void Punkte::punkten()
{punkte=plus+punkte;//here the SEGSEGV Fault happends setPlainText(QString("punkte:")+QString::number(punkte)); return;
}
int Punkte::getPunkte()
{
return punkte;
} -
@JonnyQB said in [need help SigSegv fault with normal + calculation]
that‘s most likely an incorrect jump into your source file, happens.
I‘m way more concerned about the delete this; inside a Slot of a Qobject based clas!!!
don‘t do that, rather call deleteLater() -
Hi
Are you sure that punkten-> is a valid pointer ?
You do not seem to assign to it before calling it.QList<QGraphicsItem *> colliding_items=collidingItems(); for(int i=0,n=colliding_items.size();i<n;i++) { if(typeid (*(colliding_items[i]))==typeid(Gegner)) { punkten->punkten();// where do u set punkten to anything valid ?