PDA

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



Krish
12th March 2008, 17: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: -

########sampleplot.h##########


#ifndef SAMPLEPLOT_H
#define SAMPLEPLOT_H

#include<QtGui>
#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
{
Q_OBJECT

public:
samplePlot(QWidget* parent = 0);

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

#endif


########sampleplot.cpp########


#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
curve->setPen(QPen(Qt::red));

//
// 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
//
sampleqwtPlot->replot();
}


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:)

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

jpn
13th March 2008, 07:35
You have

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

Krish
13th March 2008, 08: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.

jacek
14th March 2008, 13: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?

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

Thanks again:)

Best Regards