Please Help-->Not able to draw curves in QwtPlot Widget !
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##########
Code:
#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:
private:
// Arrays holding the values.
double xval[PLOT_SIZE];
double yval[PLOT_SIZE];
// Insert new curve
};
#endif
########sampleplot.cpp########
Code:
#include <QtGui>
#include "sampleplot.h"
samplePlot
::samplePlot( 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:)
Re: Please Help-->Not able to draw curves in QwtPlot Widget !
Could you post the exact error message? Maybe your OS can't find Qwt DLLs?
Re: Please Help-->Not able to draw curves in QwtPlot Widget !
You have
and I see it being used but never allocated. In other words, it's a dangling pointer.
Re: Please Help-->Not able to draw curves in QwtPlot Widget !
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.
Re: Please Help-->Not able to draw curves in QwtPlot Widget !
Quote:
Originally Posted by
Krish
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?
Re: Please Help-->Not able to draw curves in QwtPlot Widget !
Hello! Jacek Sir,
Thanks for taking out time and replying but i have somehow solved the problem.
Thanks again:)
Best Regards