A simple application with a ui form, generated in eclipse. I am working with Qt for about 6 months now, but still learning. The form is opened and shown after compiling. The form has a QWidget called "widget".

If I add the basic code to draw a qwtplot on the form it crashes. The mesage is: "QWidget: Must construct a QApplication before a QPaintDevice". I thought qapplication was constructed first in the main code, so I don't get it! I have tried linking the qwtplot to "this" and "parent" but the same result. I have also tried to move the plot from the constructor of class trygraph to a button press function but with the same result

In all examples of QwtPLot I can find the plot is made in the main function before "return a.exec();"
Appreciate any help or pointers to examples.

Qt Code:
  1. trygraph::trygraph(QWidget *parent)
  2. : QWidget(parent)
  3. {
  4. ui.setupUi(this);
  5.  
  6. double x[100], y1[100];
  7. QwtPlot *myPlot = new QwtPlot(QwtText("a Curves"), ui.widget);
  8.  
  9. for (int i = 0; i < 100; i++)
  10. {
  11. x[i] = i;
  12. y1[i] = 10-0.1*i*i;
  13. }
  14.  
  15. // add curves
  16. QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
  17.  
  18. // copy the data into the curves
  19. curve1->setData(x,y1,100);
  20.  
  21. curve1->attach(myPlot);
  22.  
  23. myPlot->replot();
  24. }
  25.  
  26. [the main function:]
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30. QApplication a(argc, argv);
  31. trygraph w;
  32. w.show();
  33. return a.exec();
  34. }
To copy to clipboard, switch view to plain text mode