[qwt] Plot is not displayed when using QwtPlot
-
I want to use qwt to draw plots and I'm starting with some easy examples like the one bellow.
@ QwtPlot plot = new QwtPlot();
QwtPlotCurve f = new QwtPlotCurve("Line");
double xdata[10], ydata[10] ;
for (int i = 0; i< 10; i++) {
xdata[i] = i+1;
ydata[i] = (i+1)*10;
}
f->setRawSamples(xdata,ydata,10);
f->attach(plot);
plot->replot();@The problem is that nothing happens, no window displayed.....
I use Qt 5.1.0 with mingw 4.8 and qwt 6.1 compiled also with mingw 4.8 on Windows 7 x86.
-
Hi,
Do you call show on your plot somewhere ?
Do you put it in a layout in another widget ? -
Hi,
I use that code inside a function used in a QApplication;
I have also tried to use it main function, like this:
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QwtPlot plot = new QwtPlot();
QwtPlotCurve f = new QwtPlotCurve("Line");
double xdata[10], ydata[10] ;
for (int i = 0; i< 10; i++) {
xdata[i] = i+1;
ydata[i] = (i+1)*10;
}
f->setRawSamples(xdata,ydata,10);
f->attach(plot);
plot->replot();return a.exec();
}@
-
You still don't call
@plot->show();@
You're also introducing a memory leak not deleting your plot after a.exec();
-
Thank you, that was the problem..
Do I have to manually destroy the plot, doesn't this happen when I click the Close button (in the plot widget) ? -
It only happens if you have Qt::WA_DeleteOnClose set on your widget