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. PieChart [QWidget] - Error: SIGFPE Arithmetic Problem [C++]
Forum Update on Monday, May 27th 2025

PieChart [QWidget] - Error: SIGFPE Arithmetic Problem [C++]

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 597 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.
  • N Offline
    N Offline
    NovaPrimera
    wrote on 10 Mar 2019, 21:26 last edited by NovaPrimera 3 Oct 2019, 21:38
    #1

    Dear Qt Community.

    The problem I think is within my loops,when I try to change the color of my brush to a random colour. I did try to change the resultV and other arithmetic variables ...it doesn`t help. I have a SIGFPE Arithemetic problem then Qt informs me of 'Signal Recieved' , the inferior stopped because it recieved a signal from the operating system . Signal name : ? , Signal meaning: unknown.

    Please can anyone kindly help me? [I did have problems with Qt before and had to reinstall it because my main class could not detect it`s files. I am using the lastest version of Qt] .Any help is much appreciated.

    *CHANGES:

    1. 360/sum changed to 'sum/360;' [Fixes SIGFPE Arithmetic Problem]

    **NEW PROBLEM:

    1. My codes breakpoint stops at the empty method:
      PieChartWidget::PieChartWidget(QWidget *parent) : QWidget(parent)

    Code: [piechartwidget.cpp]

    #include "piechartwidget.h"

    #include <QColor>
    #include <QPainter>

    PieChartWidget::PieChartWidget(QWidget *parent) : QWidget(parent)
    {

    }

    void PieChartWidget::paintEvent(QPaintEvent *)
    {
    QVector<int> vector(5);
    vector.append(10);
    vector.append(20);
    vector.append(5);
    vector.append(1);
    vector.append(50);

    int sum=0;
    int angleV=0;
    int resultV=0;
    int resultVV =0;
    
    QPainter painter(this);
    QRectF size = QRectF(10,10,this->width()-10,this->width()-10);
    
    int *data = vector.data();
    
    for (int i = 0; i < 5; ++i){
        sum += data[i];
    }
    
    angleV = sum/360;
    
    for (int i = 0; i < 5; ++i){
        if(i == 0){
            resultV = data[i] * angleV;
            painter.setBrush(palette().brush(QPalette::Text));
            painter.drawPie(size , 0 , resultV*16);
         }
         else {
    
            resultV = data[i] * angleV;
            resultVV = data[i-1] * angleV;
    
            painter.setBrush(palette().brush(QPalette::Text));
    
            painter.drawPie(size , resultVV*16 , resultV*16);
        }
    }
    

    }

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 10 Mar 2019, 23:08 last edited by
      #2

      Hi
      Good you fixed the SIGFPE, but im not sure why its an issue
      it stops at the constructor?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 11 Mar 2019, 07:15 last edited by
        #3

        Hi and welcome to devnet,

        @NovaPrimera said in PieChart [QWidget] - Error: SIGFPE Arithmetic Problem [C++]:

        360/sum changed to 'sum/360;' [Fixes SIGFPE Arithmetic Problem]

        You know that these two statements are not equivalent ? A division is not a permutative operation.

        What you need to do here is check that sum is not zero and if it is, don't do the division.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply 11 Mar 2019, 11:33
        2
        • S SGaist
          11 Mar 2019, 07:15

          Hi and welcome to devnet,

          @NovaPrimera said in PieChart [QWidget] - Error: SIGFPE Arithmetic Problem [C++]:

          360/sum changed to 'sum/360;' [Fixes SIGFPE Arithmetic Problem]

          You know that these two statements are not equivalent ? A division is not a permutative operation.

          What you need to do here is check that sum is not zero and if it is, don't do the division.

          N Offline
          N Offline
          NovaPrimera
          wrote on 11 Mar 2019, 11:33 last edited by
          #4

          @SGaist Thank you,Sir that was my problem all along.

          1 Reply Last reply
          0

          1/4

          10 Mar 2019, 21:26

          • Login

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