View Full Version : Please Help-->Not able to draw curves in QwtPlot Widget !

12th March 2008, 16:01
Hello! Friends,
I am using Qwt plugin with Qt4.3.4 in WinXP to design a GUI. Now i have created a Widget in Qt, added QwtPlot Widget to it named sampleqwtPlot and coded the following files: -



#include <qwt_plot.h>
#include <qwt_plot_curve.h>

#include "ui_sampleplot.h"

const int PLOT_SIZE = 101;

class samplePlot : public QWidget, private Ui::sampleForm

samplePlot(QWidget* parent = 0);

// Arrays holding the values.
double xval[PLOT_SIZE];
double yval[PLOT_SIZE];
// Insert new curve
QwtPlotCurve *curve;



#include <QtGui>
#include "sampleplot.h"

samplePlot::samplePlot( QWidget *parent )
: QWidget( parent )
setupUi(this); // this sets up GUI
connect( startPushButton, SIGNAL( clicked() ), this, SLOT( draw_curve() ) );

// Axis
sampleqwtPlot->setAxisTitle(QwtPlot::xBottom, "Time/seconds");
sampleqwtPlot->setAxisScale(QwtPlot::xBottom, 0, 100);

sampleqwtPlot->setAxisTitle(QwtPlot::yLeft, "Values");
sampleqwtPlot->setAxisScale(QwtPlot::yLeft, 0, 50);

// Set curve styles

// Calculate values
for(int i=0;i<PLOT_SIZE;i++)
xval[i] = i;
yval[i] = 0.5*i;
//Assign values to the curve.
curve->setData( xval, yval, PLOT_SIZE );
//Attach the curve.
curve->attach( sampleqwtPlot );
// finally, refresh the plot

I am able to get the sampleplot.exe file but its not working, like whenever i try to run it, displays error "encountered a problem".

I think i am making a small silly mistake somewhere.:confused:

Can anyone please help me out.--> I will be obliged:)

13th March 2008, 00:27
Could you post the exact error message? Maybe your OS can't find Qwt DLLs?

13th March 2008, 06:35
You have

QwtPlotCurve *curve;
and I see it being used but never allocated. In other words, it's a dangling pointer.

13th March 2008, 07:36
Hello! Jacek & Jpn,
Thanks for taking out time and helping me out. I had made a same mistake as said by Jpn. But now i did few things and its working!!:)

But now i added a pushbutton to clear the drawn plot but its not clearing the curves n all, i dont know why? Even though i have properly connected it to sampleqwtPlot->clear() slot, its not working.:( I mean replot() slot is working but clear() slot is not!!!!:confused:

Also i tried to connect the same button to Form->close() slot, and its working but samplePlot->clear() slot isn't????

Thanks again.

Best Regards.

14th March 2008, 12:06
Also i tried to connect the same button to Form->close() slot, and its working but samplePlot->clear() slot isn't????
How did you declare samplePlot::clear() and how do you establish the connection?

18th March 2008, 16:11
Hello! Jacek Sir,
Thanks for taking out time and replying but i have somehow solved the problem.

Thanks again:)

Best Regards