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:
private:
// Arrays holding the values.
double xval[PLOT_SIZE];
double yval[PLOT_SIZE];
// Insert new curve
};
#endif
#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
To copy to clipboard, switch view to plain text mode
########sampleplot.cpp########
#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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
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.
Can anyone please help me out.--> I will be obliged
Bookmarks