PDA

View Full Version : my programm crach with this code



yazan
18th September 2011, 15:08
hi all,
can anybody tell me what is worng with this code:
i have taken the code from this thread http://www.qtcentre.org/threads/40428-Gantt-charts-with-QWT?highlight=QwtIntervalSymbol



i'm trying to draw a curve where every point will be with errorbars. but wen i run the code the programm crash.
messgraphFrame::messgraphFrame(QWidget *parent) :
QFrame(parent),
ui(new Ui::messgraphFrame)
{
ui->setupUi(this);
QVector<QwtIntervalSample> samples(3);
samples.append( QwtIntervalSample( 10 ,QwtInterval( 8, 12 )) );
samples.append( QwtIntervalSample( 2,QwtInterval( 3, 7 )) );
samples.append( QwtIntervalSample( 18,QwtInterval( 17, 20 )) );

QwtIntervalSymbol symbol( QwtIntervalSymbol::Bar );
// QwtPlot *myPlot = new QwtPlot( NULL );

QwtPlotIntervalCurve *curve1 = new QwtPlotIntervalCurve("Curve 1");
curve1->setSymbol( &symbol );
curve1->setSamples( samples );
curve1->attach(this->ui->qwtPlot);
// curve1->setStyle( QwtPlotIntervalCurve::Tube );
this->ui->qwtPlot->replot ();

}

Kangs
18th September 2011, 16:21
QwtIntervalSymbol symbol( QwtIntervalSymbol::Bar );
// QwtPlot *myPlot = new QwtPlot( NULL );

QwtPlotIntervalCurve *curve1 = new QwtPlotIntervalCurve("Curve 1");
curve1->setSymbol( &symbol );

Try to use a pointer for symbol


QwtIntervalSymbol* symbol = new QwtIntervalSymbol( QwtIntervalSymbol::Bar );
// QwtPlot *myPlot = new QwtPlot( NULL );

QwtPlotIntervalCurve *curve1 = new QwtPlotIntervalCurve("Curve 1");
curve1->setSymbol( symbol );

yazan
18th September 2011, 16:33
thank you for your reply but it did not work.
i have found that the crash happens when i attach the curve to the plot.
but tel now i did not understand why.

stampede
18th September 2011, 19:05
Build debug version and run it with debugger, after the crash post the backtrace.

Uwe
18th September 2011, 19:08
Kangs hint is absolutely necessary - the symbol needs to be allocated by new. The rest of the code looks o.k.

When you have fixed your code and your application still crashes, use your debugger and show the call stack.

Uwe

yazan
18th September 2011, 20:57
thank you all it work