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:
Qt Code:
  1. #ifndef PLOTM_H
  2.  
  3. #define PLOTM_H
  4. #include "ui_Plot10.h"
  5. #include <qdialog.h>
  6.  
  7. class Plotm : public QMainWindow, public Ui::MainWindow
  8. {
  9.  
  10. Q_OBJECT
  11.  
  12. public:
  13.  
  14. Plotm (QMainWindow *parent = 0);
  15.  
  16. ~ Plotm ();
  17.  
  18. private slots:
  19.  
  20. void draw();
  21. };
  22.  
  23. #endif //PLOTM_H
To copy to clipboard, switch view to plain text mode 
Plotm.cpp:
Qt Code:
  1. #include "Plotm.h"
  2. #include "Plot.h"
  3.  
  4.  
  5. Plotm::Plotm(QMainWindow *parent) : QMainWindow(parent)
  6. {
  7. setupUi(this);
  8. xmi-> setText("0");
  9. ymi-> setText("0");
  10.  
  11. connect(plotb, SIGNAL(clicked()), this, SLOT(draw()));
  12. }
  13.  
  14. Plotm::~Plotm()
  15. {}
  16.  
  17. void Plotm::draw()
  18. {
  19. Graph* plot ;
  20. QDialog* nw;
  21. nw = new QDialog(this, Qt::Window);
  22.  
  23. int ava; //Gradient
  24. int bva; //Offset
  25.  
  26. ava = aval->text().toDouble();
  27. bva = bval->text().toDouble();
  28.  
  29.  
  30. plot = new Graph(ava,bva,nw);
  31. plot->show();
  32. nw->show();
  33. }
To copy to clipboard, switch view to plain text mode 

Plot.h:
Qt Code:
  1. #ifndef PLOT_H
  2. #define PLOT_H
  3.  
  4. #include <qapplication.h>
  5. #include <qlayout.h>
  6. #include <qwt_plot.h>
  7. #include <qwt_plot_marker.h>
  8. #include <qwt_plot_curve.h>
  9. #include <qwt_legend.h>
  10. #include <qwt_series_data.h>
  11. #include <qwt_plot_canvas.h>
  12. #include <qwt_plot_panner.h>
  13. #include <qwt_plot_magnifier.h>
  14. #include <qwt_text.h>
  15. #include <qwt_math.h>
  16. #include <math.h>
  17. #include <qwt_symbol.h>
  18. #include <QtGui>
  19.  
  20. class Graph : public QwtPlot
  21. {
  22.  
  23. public:
  24. int aval;//Gradient
  25. int bval;//Offset
  26.  
  27. double xval[100];
  28. double yval[100];
  29.  
  30. //Constructor which commits the parameters of the straight line to create
  31. Graph(int avala,int bvala, QWidget* parent);
  32. };
  33.  
  34. #endif
To copy to clipboard, switch view to plain text mode 
Plot.cpp:
Qt Code:
  1. #include <qapplication.h>
  2. #include <qlayout.h>
  3. #include <qwt_plot.h>
  4. #include <qwt_plot_marker.h>
  5. #include <qwt_plot_curve.h>
  6. #include <qwt_legend.h>
  7. #include <qwt_series_data.h>
  8. #include <qwt_plot_canvas.h>
  9. #include <qwt_plot_panner.h>
  10. #include <qwt_plot_magnifier.h>
  11. #include <qwt_text.h>
  12. #include <qwt_math.h>
  13. #include <math.h>
  14. #include <qwt_symbol.h>
  15. #include "Plot.h"
  16. #include <qwt_plot_grid.h>
  17. #include "Plotm.h"
  18. #include "Plot.h"
  19.  
  20.  
  21. Graph::Graph(int avala,int bvala,QWidget *parent)
  22. {
  23.  
  24. aval = avala;
  25. bval = bvala;
  26.  
  27. setAutoFillBackground( true );
  28. setPalette( QPalette( QColor( 165, 193, 228 ) ) );
  29.  
  30. setTitle("Plot 1.0");
  31. insertLegend(new QwtLegend(), QwtPlot::RightLegend);
  32.  
  33. // axes
  34. setAxisTitle(xBottom, "x -->" );
  35. setAxisScale(xBottom, 0, 10);
  36.  
  37. setAxisTitle(yLeft, "y -->");
  38. setAxisScale(yLeft, 0, 10);
  39.  
  40. // canvas
  41. canvas()->setLineWidth( 1 );
  42. canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
  43. canvas()->setBorderRadius( 15 );
  44.  
  45. QPalette canvasPalette( Qt::white );
  46. canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
  47. canvas()->setPalette( canvasPalette );
  48.  
  49. for(int i=0; i<100;i++)
  50. {
  51. xval[i] = double(i) * 1/10;
  52. yval[i] = this->aval * xval[i] + this->bval;
  53. }
  54.  
  55. // Insert new curves
  56.  
  57. QwtPlotCurve * d_curves = new QwtPlotCurve("y = a*x+b");
  58. d_curves->setRenderHint(QwtPlotItem::RenderAntialiased);
  59. d_curves->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
  60. d_curves->setPen(QPen(Qt::green));
  61. d_curves->setRawSamples(xval, yval, 100);
  62. d_curves->attach(this);
  63.  
  64. replot();
  65. }
To copy to clipboard, switch view to plain text mode