Hello,
I am new to the world of GUI and I am having some problems with building a programm to plot straight lines.
It would be very nice, if somebody could help me... 
I am using Visual Studio 2010 Express.
Both Qt and QWT are succesfully integrated and are tested to work properly.
I thought it wold work like this:
- The parameters (Offset + Gradient) of the straight line are committed in the Main Window
- Pushing the Plot-Button should call a Constructor, that creates a QWT PLot, called Graph,
and inserts a straight line with the committed paramters. (Plot.h/cpp)
- Furthermore a QDialog should be created
-The previously created Graph should now be inserted in the QDialog
- After all the new Window should open and display the straight line
My Problem is, that after succesfully compiling and linking the mainwindow opens, but pushing the plot-button
results in the programms shutdown with errorcode 1.
If I leave out the call of the Graph constructor in Plotm::draw, the programm runs completely succesfully but the new window is empty of course.
So in my oppinion I do something wrong in the constructor...
Thank you for your help !
Plotm.h:
#ifndef PLOTM_H
#define PLOTM_H
#include "ui_Plot10.h"
#include <qdialog.h>
class Plotm
: public QMainWindow,
public Ui
::MainWindow{
Q_OBJECT
public:
~ Plotm ();
private slots:
void draw();
};
#endif //PLOTM_H
#ifndef PLOTM_H
#define PLOTM_H
#include "ui_Plot10.h"
#include <qdialog.h>
class Plotm : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
Plotm (QMainWindow *parent = 0);
~ Plotm ();
private slots:
void draw();
};
#endif //PLOTM_H
To copy to clipboard, switch view to plain text mode
Plotm.cpp:
#include "Plotm.h"
#include "Plot.h"
{
setupUi(this);
xmi-> setText("0");
ymi-> setText("0");
connect(plotb, SIGNAL(clicked()), this, SLOT(draw()));
}
Plotm::~Plotm()
{}
void Plotm::draw()
{
Graph* plot ;
nw
= new QDialog(this, Qt
::Window);
int ava; //Gradient
int bva; //Offset
ava = aval->text().toDouble();
bva = bval->text().toDouble();
plot = new Graph(ava,bva,nw);
plot->show();
nw->show();
}
#include "Plotm.h"
#include "Plot.h"
Plotm::Plotm(QMainWindow *parent) : QMainWindow(parent)
{
setupUi(this);
xmi-> setText("0");
ymi-> setText("0");
connect(plotb, SIGNAL(clicked()), this, SLOT(draw()));
}
Plotm::~Plotm()
{}
void Plotm::draw()
{
Graph* plot ;
QDialog* nw;
nw = new QDialog(this, Qt::Window);
int ava; //Gradient
int bva; //Offset
ava = aval->text().toDouble();
bva = bval->text().toDouble();
plot = new Graph(ava,bva,nw);
plot->show();
nw->show();
}
To copy to clipboard, switch view to plain text mode
Plot.h:
#ifndef PLOT_H
#define PLOT_H
#include <qapplication.h>
#include <qlayout.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include <math.h>
#include <qwt_symbol.h>
#include <QtGui>
{
public:
int aval;//Gradient
int bval;//Offset
double xval[100];
double yval[100];
//Constructor which commits the parameters of the straight line to create
Graph
(int avala,
int bvala,
QWidget* parent
);
};
#endif
#ifndef PLOT_H
#define PLOT_H
#include <qapplication.h>
#include <qlayout.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include <math.h>
#include <qwt_symbol.h>
#include <QtGui>
class Graph : public QwtPlot
{
public:
int aval;//Gradient
int bval;//Offset
double xval[100];
double yval[100];
//Constructor which commits the parameters of the straight line to create
Graph(int avala,int bvala, QWidget* parent);
};
#endif
To copy to clipboard, switch view to plain text mode
Plot.cpp:
#include <qapplication.h>
#include <qlayout.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include <math.h>
#include <qwt_symbol.h>
#include "Plot.h"
#include <qwt_plot_grid.h>
#include "Plotm.h"
#include "Plot.h"
Graph
::Graph(int avala,
int bvala,
QWidget *parent
) {
aval = avala;
bval = bvala;
setAutoFillBackground( true );
setTitle("Plot 1.0");
// axes
setAxisTitle(xBottom, "x -->" );
setAxisScale(xBottom, 0, 10);
setAxisTitle(yLeft, "y -->");
setAxisScale(yLeft, 0, 10);
// canvas
canvas()->setLineWidth( 1 );
canvas()->setBorderRadius( 15 );
canvasPalette.
setColor( QPalette::Foreground,
QColor( 133,
190,
232 ) );
canvas()->setPalette( canvasPalette );
for(int i=0; i<100;i++)
{
xval[i] = double(i) * 1/10;
yval[i] = this->aval * xval[i] + this->bval;
}
// Insert new curves
d_curves
->setRenderHint
(QwtPlotItem::RenderAntialiased);
d_curves
->setLegendAttribute
(QwtPlotCurve::LegendShowLine,
true);
d_curves
->setPen
(QPen(Qt
::green));
d_curves->setRawSamples(xval, yval, 100);
d_curves->attach(this);
replot();
}
#include <qapplication.h>
#include <qlayout.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include <math.h>
#include <qwt_symbol.h>
#include "Plot.h"
#include <qwt_plot_grid.h>
#include "Plotm.h"
#include "Plot.h"
Graph::Graph(int avala,int bvala,QWidget *parent)
{
aval = avala;
bval = bvala;
setAutoFillBackground( true );
setPalette( QPalette( QColor( 165, 193, 228 ) ) );
setTitle("Plot 1.0");
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
// axes
setAxisTitle(xBottom, "x -->" );
setAxisScale(xBottom, 0, 10);
setAxisTitle(yLeft, "y -->");
setAxisScale(yLeft, 0, 10);
// canvas
canvas()->setLineWidth( 1 );
canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
canvas()->setBorderRadius( 15 );
QPalette canvasPalette( Qt::white );
canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
canvas()->setPalette( canvasPalette );
for(int i=0; i<100;i++)
{
xval[i] = double(i) * 1/10;
yval[i] = this->aval * xval[i] + this->bval;
}
// Insert new curves
QwtPlotCurve * d_curves = new QwtPlotCurve("y = a*x+b");
d_curves->setRenderHint(QwtPlotItem::RenderAntialiased);
d_curves->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
d_curves->setPen(QPen(Qt::green));
d_curves->setRawSamples(xval, yval, 100);
d_curves->attach(this);
replot();
}
To copy to clipboard, switch view to plain text mode
Bookmarks