Results 1 to 4 of 4

Thread: A simple Plot doesn't work in Qt5

  1. #1
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default A simple Plot doesn't work in Qt5

    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.

  2. #2
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: A simple Plot doesn't work in Qt5

    Looks like you are using the release version of the lib in a debug app

    In the pro file try

    LIBS += -L$${QWT_LOCATION}/lib -lqwtd

    note the -lqwtd instead of -lqwt

  3. The following user says thank you to Cah for this useful post:

    8Observer8 (15th January 2014)

  4. #3
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: A simple Plot doesn't work in Qt5

    Quote Originally Posted by Cah View Post
    Looks like you are using the release version of the lib in a debug app

    In the pro file try

    LIBS += -L$${QWT_LOCATION}/lib -lqwtd

    note the -lqwtd instead of -lqwt
    Yes, It works! Thank you very much

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A simple Plot doesn't work in Qt5


  6. The following user says thank you to Uwe for this useful post:

    8Observer8 (16th January 2014)

Similar Threads

  1. Replies: 1
    Last Post: 17th December 2010, 09:53
  2. Replies: 0
    Last Post: 18th March 2010, 15:35
  3. Replies: 2
    Last Post: 5th September 2009, 12:23
  4. Replies: 12
    Last Post: 5th July 2009, 17:03
  5. QHttp simple program doesn't work
    By johncharlesb in forum Qt Programming
    Replies: 0
    Last Post: 4th April 2008, 05:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.