PieChart [QWidget] - Error: SIGFPE Arithmetic Problem [C++]
-
wrote on 10 Mar 2019, 21:26 last edited by NovaPrimera 3 Oct 2019, 21:38
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:
- 360/sum changed to 'sum/360;' [Fixes SIGFPE Arithmetic Problem]
**NEW PROBLEM:
- 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); } }
}
-
Hi
Good you fixed the SIGFPE, but im not sure why its an issue
it stops at the constructor? -
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. -
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.wrote on 11 Mar 2019, 11:33 last edited by@SGaist Thank you,Sir that was my problem all along.
1/4