PDA

View Full Version : Qwt clear() makes the graph crash



Momergil
2nd August 2011, 15:44
Hello!

I'm having a problem with Qwt::clear() in my software. Essentialy, here is the scene:

My software (QMainWindow-based) has three widgets in wich three Qwt:: plot are included (via "ui"). I put a button in the Menu_bar that should clear all data in the graphs (i.e. all the lines and curves that were plotted) and I figured out that the code for doing so would be:


gra->plot->clear();
gra->plot->replot();

gra2->plot->clear();
gra2->plot->replot();

gra3->plot->clear();
gra3->plot->replot();

(gra, gra2 and gra3 are the graphs from graf.cpp, which creates the each one a QwtPlot plot).


The problem is that, while when a click the button everything runs fine (i.e. the curve is indeed deleted), when I put new data to be plot, the software crash and gives no specific message saying what is the error.

I already did enough tests that demonstrates that is the clear() function that is leading to the crash, not the plot() or any other thing in the system.


Do somebody know how to solve the problem? In any case, I may put more code for you to analyze.



Thanks!

Martin/Momergil

Uwe
2nd August 2011, 17:54
The problem is that, while when a click the button everything runs fine (i.e. the curve is indeed deleted), when I put new data to be plot, the software crash and gives no specific message saying what is the error.

Should be a problem of new/delete of your plot items and maybe the inserted data objects. Ask your debugger, what is wrong.

Uwe

Momergil
3rd August 2011, 18:46
Should be a problem of new/delete of your plot items and maybe the inserted data objects. Ask your debugger, what is wrong.

Uwe

Well, I'll try somethign like calling a function to do the clear() istead of calling it directly as I'm doing with this version. Now I tried the "ask your debugger" [with what I understood by that] and the message was:


The inferior stopped because it received a signal from the Operating System.

Signal name : SIGSEGV
Signal meaning : Segmentation fault


Than it pointed out to line 306 in my programming in the cpp that makes the new points:


pmw->gra->curva->setData(&xs1[0],&ys1[0],xs1.size());

How should I proceed in this case?

Uwe
3rd August 2011, 23:03
Segmentation fault is usually a bad pointer - should be one of the 3 pointers used on this line.

Ask your debugger,

Uwe

Momergil
24th August 2011, 21:06
Segmentation fault is usually a bad pointer - should be one of the 3 pointers used on this line.

Ask your debugger,

Uwe

Well, I corrected a problem regarding the first pointer, run the debugger but the problem persist in the same code line.

I have the impression, though, that you are right in saying "Should be a problem of new/delete of your plot items". I noticed that by simply putting clear() and replot() the graph is not really re-initialized; its just made clean.

Do you know what exactly should I do to not just clean the graph, but also make it return to the beginning, as if it was new?


Momergil