Hello, I'm trying to learn how to use Qwt and I'm stucked with one problem.

When I create a custom application with just main function everything works fine. (the code is based on examples from qwt)

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QApplication a(argc, argv);
  4.  
  5. double x[100];
  6. double y[100];
  7.  
  8. for(int i=0;i<100;i++)
  9. {
  10. x[i] = i/20.0;
  11. y[i] = sin(x[i]);
  12. }
  13. QHBoxLayout *layout = new QHBoxLayout(&w);
  14. layout->setContentsMargins( 0, 0, 0, 0 );
  15. QwtPlot *myPlot = new QwtPlot(&w);
  16. myPlot->setMinimumSize(w.geometry().width()-20,w.geometry().height()-20);
  17. // add curve
  18. QwtPlotCurve *curve = new QwtPlotCurve();
  19. curve->setRawSamples(x, y, 100);
  20. curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
  21. QPen(Qt::black), QSize(5, 5) ) );
  22. curve->setPen(QColor(Qt::darkGreen));
  23. curve->setStyle(QwtPlotCurve::Lines);
  24. curve->setCurveAttribute(QwtPlotCurve::Fitted);
  25. curve->attach(myPlot);
  26. QPushButton *b = new QPushButton(&w);
  27. layout->addWidget(myPlot);
  28. layout->addWidget(b);
  29. w.setLayout(layout);
  30. w.show();
  31.  
  32. return a.exec();
  33. }
To copy to clipboard, switch view to plain text mode 

The problem is when i try to copy this part of code and put it in MainWindow designed in QtCreator.

Qt Code:
  1. void MainWindow::initGraph()
  2. {
  3. double x[100];
  4. double y[100];
  5.  
  6. for(int i=0;i<100;i++)
  7. {
  8. x[i] = i/100.0;
  9. y[i] = sin(x[i]);
  10. }
  11. QHBoxLayout *layout = new QHBoxLayout(ui->widget);
  12. layout->setContentsMargins( 0, 0, 0, 0 );
  13. QwtPlot *myPlot = new QwtPlot(ui->widget);
  14. myPlot->setMinimumSize(ui->widget->geometry().width()-20,ui->widget->geometry().height()-20);
  15. myPlot->updateGeometry();
  16. // add curves
  17. QwtPlotCurve *curve = new QwtPlotCurve();
  18. curve->setRawSamples(x, y, 100);
  19. curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
  20. QPen(Qt::black), QSize(5, 5) ) );
  21. curve->setPen(QColor(Qt::darkGreen));
  22. curve->setStyle(QwtPlotCurve::Lines);
  23. curve->setCurveAttribute(QwtPlotCurve::Fitted);
  24. curve->attach(myPlot);
  25. myPlot->autoReplot();
  26. myPlot->replot();
  27. myPlot->autoRefresh();
  28. layout->addWidget(myPlot);
  29. ui->widget->setLayout(layout);
  30. }
  31.  
  32. //and main
  33.  
  34. int main(int argc, char *argv[])
  35. {
  36. QApplication a(argc, argv);
  37. MainWindow w;
  38. w.initGraph();
  39. w.show();
  40.  
  41. return a.exec();
  42. }
To copy to clipboard, switch view to plain text mode 

After running code above I see my app, axis of the plot are scaled but curve is not painted properly (I think only first point is painted). I tried couple of functions from plot to fix it (as you can see in code above). I've created 2 or 3 gui apps using qtCreator's designer and even with just 1 main widget it doesn't work fine. Could anyone tell me where do I make a mistake and how to fix that problem?

Sorry if someone finds it hard to understand what I've written here but english is not my native language.