Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. need help SigSegv fault with normal + calculation
QtWS25 Last Chance

need help SigSegv fault with normal + calculation

Scheduled Pinned Locked Moved Solved General and Desktop
sigsegvfaultsignalsslotclass
9 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JonnyQB
    wrote on last edited by JonnyQB
    #1

    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;
    }

    J.HilkJ 1 Reply Last reply
    0
    • J JonnyQB

      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;
      }

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @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()


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      J 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @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()

        J Offline
        J Offline
        JonnyQB
        wrote on last edited by
        #3

        @J-Hilk
        ok i will try this

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JonnyQB
          wrote on last edited by
          #4

          now i tried it with global but there is the same problem

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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 ?
            
            1 Reply Last reply
            2
            • J Offline
              J Offline
              JonnyQB
              wrote on last edited by
              #6

              im my header file

              class Munition : public QObject,public QGraphicsRectItem
              {
              Q_OBJECT
              public:
              Punkte * punkten;
              Munition();
              public slots:
              void move();

              };

              #endif // MUNITION_H

              mrjjM 1 Reply Last reply
              0
              • J JonnyQB

                im my header file

                class Munition : public QObject,public QGraphicsRectItem
                {
                Q_OBJECT
                public:
                Punkte * punkten;
                Munition();
                public slots:
                void move();

                };

                #endif // MUNITION_H

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @JonnyQB
                Hi
                That is a dangling pointer.
                It will point to random memory.
                So if you do not assign it anywhere, that is the reason you crash.

                Like
                punkten = new Punkte();

                J 1 Reply Last reply
                3
                • mrjjM mrjj

                  @JonnyQB
                  Hi
                  That is a dangling pointer.
                  It will point to random memory.
                  So if you do not assign it anywhere, that is the reason you crash.

                  Like
                  punkten = new Punkte();

                  J Offline
                  J Offline
                  JonnyQB
                  wrote on last edited by JonnyQB
                  #8

                  @mrjj
                  as what schould i declare it
                  punkten=new Punkte(); got the c++ requiers a type specifier...

                  mrjjM 1 Reply Last reply
                  0
                  • J JonnyQB

                    @mrjj
                    as what schould i declare it
                    punkten=new Punkte(); got the c++ requiers a type specifier...

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @JonnyQB
                    Hi
                    You declare it like
                    Punkte * punkten;

                    Then some place else you must do
                    punkten = new Punkte(); ( not in .h)
                    Often the constructor is a good place.

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved