PDA

View Full Version : Qt Program with SIGSEGV error...



marcos.miranda
31st August 2017, 18:26
Hello everyone...
I'm having a little problem with a program I'm working on.
As I have no QT experience, my head warms up ...

I try to select text in a pdf file, time works, time does not work and crash program.

I made a video to help understand, at first the selection of the text works, then begins to give problem with the message "SIGSEGV".

I think the problem is in this line:


This-> scene () -> update (boundingRect ().Translated (pos ()));

Follow the video link of the Error.


https://youtu.be/Qofs9OEGd6c

How to handle this error?

Can someone help me ? Thanks in advance.

d_stranz
31st August 2017, 19:58
Why don't you post some real code instead of videos? Posting a single line is useless without some idea of the context in which it is called.

My guess is that the call to "scene()" returns a NULL pointer (which you don't check for). Examine the value returned by the call to scene(). If it is OK, then something could be going wrong inside of the update() call.

marcos.miranda
31st August 2017, 21:25
Hi, D_Stranz.

Follow the requested code, sorry for the lack of attention.
I had already separated the code. :rolleyes:



void PageObject::mouseMoveEvent(QGraphicsSceneMouseEven t *event)
{
if(!m_rubberBand.isNull())
{
m_rubberBand.setBottomRight(event->scenePos() - pos());

this->updatePage();
}
}


QRectF PageObject::boundingRect() const
{
QRectF result;

qreal scaleX = m_view->resolutionX() / 72.0;
qreal scaleY = m_view->resolutionY() / 72.0;
qreal width = m_size.width();
qreal height = m_size.height();

switch(m_view->rotation())
{
case DocumentView::RotateBy0:
case DocumentView::RotateBy180:
result = QRectF(0.0, 0.0, qCeil(scaleX * width), qCeil(scaleY * height));

break;
case DocumentView::RotateBy90:
case DocumentView::RotateBy270:
result = QRectF(0.0, 0.0, qCeil(scaleX * height), qCeil(scaleY * width));

break;
}

return result;
}


void PageObject::updatePage()
{
this->scene()->update(boundingRect().translated(pos()));
}

high_flyer
1st September 2017, 10:12
I think the problem is in this line:

Run the application in a debugger and you won't need to guess, the debugger will stop on the offending line so we know for sure.
From there is will easy to point to the bug.

marcos.miranda
5th September 2017, 12:28
Run the application in a debugger and you won't need to guess, the debugger will stop on the offending line so we know for sure.
From there is will easy to point to the bug.

Dear, high_flyer.

Actually you're very sure, I was already using debug mode and the offending line that the debugger accuses is this.
What I meant by "I think the problem is this line" is that sometimes the error is in another function that has not received treatment and passes inconsistent information that causes error in the other function that calls it.
In this problem we have some nested functions, but thanks for the tip.

high_flyer
5th September 2017, 12:29
Its your turn to answer, see my last post.

marcos.miranda
5th September 2017, 12:39
My guess is that the call to "scene()" returns a NULL pointer (which you don't check for). Examine the value returned by the call to scene(). If it is OK, then something could be going wrong inside of the update() call.


Dear, D_Stranz.

I tried to handle the error with the code below but it did not work.
I tested it with "isnull (), isempty and isvalid()".



if (! boundingRect () translated (pos ()) isNull () ||! boundingRect () .translated (pos ()) isValid ());
{
this-> scene () -> update (boundingRect (). translated (pos ()));
}


Could it show you how to validate before calling the line "this-> scene ()->Update() ...."?

d_stranz
5th September 2017, 23:13
if (! boundingRect () translated (pos ()) isNull () ||! boundingRect () .translated (pos ()) isValid ());

This code is complete nonsense.

As I said, you don't check that the call to scene() returns a valid pointer. I hope you understand how to compare the return value of a function to NULL.