Hi,

A simple Plot doesn't work in Qt5. Please, help me!

SimplePlotInQt5.pro

Qt Code:
  1. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  2.  
  3. SOURCES += \
  4. main.cpp \
  5. plotwindow.cpp
  6.  
  7. HEADERS += \
  8. plotwindow.h
  9.  
  10. QWT_LOCATION = c:/Qwt-6.1.0
  11. INCLUDEPATH += $${QWT_LOCATION}/include
  12. LIBS = -L$${QWT_LOCATION}/lib \
  13. -lqwt
To copy to clipboard, switch view to plain text mode 

plotwindow.h
Qt Code:
  1. #ifndef PLOTHWINDOW_H
  2. #define PLOTWINDOW_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. class PlotWindow : public QMainWindow
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit PlotWindow(QWidget *parent = 0);
  11.  
  12. signals:
  13.  
  14. public slots:
  15.  
  16. };
  17.  
  18. #endif // PLOTWINDOW_H
To copy to clipboard, switch view to plain text mode 

plotwindow.cpp
Qt Code:
  1. #include "plotwindow.h"
  2. #include <qwt_plot.h>
  3. #include <qwt_legend.h>
  4. #include <qwt_plot_grid.h>
  5. #include <qwt_plot_curve.h>
  6. #include <qwt_symbol.h>
  7. #include <QHBoxLayout>
  8. #include <QWidget>
  9.  
  10. PlotWindow::PlotWindow(QWidget *parent) :
  11. QMainWindow(parent)
  12. {
  13. QwtPlot *plot = new QwtPlot;
  14.  
  15. plot->setTitle(tr("Simple Plot"));
  16. plot->setCanvasBackground(Qt::white);
  17. plot->setAxisScale(QwtPlot::yLeft, 0.0, 100);
  18. plot->insertLegend(new QwtLegend);
  19.  
  20. QwtPlotGrid *grid = new QwtPlotGrid;
  21. grid->attach(plot);
  22.  
  23. QwtPlotCurve *curve = new QwtPlotCurve;
  24. curve->setTitle(tr("Points"));
  25. curve->setPen(QPen(Qt::blue, 4));
  26. curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
  27.  
  28. QwtSymbol *symbol = new QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::yellow),
  29. QPen(Qt::red, 2), QSize(8, 8));
  30. curve->setSymbol(symbol);
  31.  
  32. QPolygonF points;
  33. points << QPointF(0.0, 0.0) << QPointF(200.0, 20.0) << QPointF(400, 40) <<
  34. QPointF(600.0, 40) << QPointF(1000.0, 100.0);
  35.  
  36. curve->setSamples(points);
  37. curve->attach(plot);
  38.  
  39. QHBoxLayout *mainLayout = new QHBoxLayout;
  40. mainLayout->addWidget(plot);
  41.  
  42. QWidget *window = new QWidget;
  43. window->setLayout(mainLayout);
  44.  
  45. setCentralWidget(window);
  46.  
  47. this->setWindowTitle(tr("Simple Plot"));
  48. this->resize(600, 400);
  49. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QApplication>
  2. #include "plotwindow.h"
  3.  
  4. int main(int argc, char **argv)
  5. {
  6. QApplication app(argc, argv);
  7.  
  8. PlotWindow gw;
  9. gw.show();
  10.  
  11. return app.exec();
  12. }
To copy to clipboard, switch view to plain text mode 

Output
QWidget: Must construct a QApplication before a QPaintDevice
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.