PDA

View Full Version : A simple Plot doesn't work in Qt5



8Observer8
7th December 2013, 07:26
Hi,

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

SimplePlotInQt5.pro



greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

SOURCES += \
main.cpp \
plotwindow.cpp

HEADERS += \
plotwindow.h

QWT_LOCATION = c:/Qwt-6.1.0
INCLUDEPATH += $${QWT_LOCATION}/include
LIBS = -L$${QWT_LOCATION}/lib \
-lqwt


plotwindow.h


#ifndef PLOTHWINDOW_H
#define PLOTWINDOW_H

#include <QMainWindow>

class PlotWindow : public QMainWindow
{
Q_OBJECT
public:
explicit PlotWindow(QWidget *parent = 0);

signals:

public slots:

};

#endif // PLOTWINDOW_H


plotwindow.cpp


#include "plotwindow.h"
#include <qwt_plot.h>
#include <qwt_legend.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <QHBoxLayout>
#include <QWidget>

PlotWindow::PlotWindow(QWidget *parent) :
QMainWindow(parent)
{
QwtPlot *plot = new QwtPlot;

plot->setTitle(tr("Simple Plot"));
plot->setCanvasBackground(Qt::white);
plot->setAxisScale(QwtPlot::yLeft, 0.0, 100);
plot->insertLegend(new QwtLegend);

QwtPlotGrid *grid = new QwtPlotGrid;
grid->attach(plot);

QwtPlotCurve *curve = new QwtPlotCurve;
curve->setTitle(tr("Points"));
curve->setPen(QPen(Qt::blue, 4));
curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);

QwtSymbol *symbol = new QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::yellow),
QPen(Qt::red, 2), QSize(8, 8));
curve->setSymbol(symbol);

QPolygonF points;
points << QPointF(0.0, 0.0) << QPointF(200.0, 20.0) << QPointF(400, 40) <<
QPointF(600.0, 40) << QPointF(1000.0, 100.0);

curve->setSamples(points);
curve->attach(plot);

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(plot);

QWidget *window = new QWidget;
window->setLayout(mainLayout);

setCentralWidget(window);

this->setWindowTitle(tr("Simple Plot"));
this->resize(600, 400);
}


main.cpp


#include <QApplication>
#include "plotwindow.h"

int main(int argc, char **argv)
{
QApplication app(argc, argv);

PlotWindow gw;
gw.show();

return app.exec();
}


Output


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

Cah
15th January 2014, 19:37
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

8Observer8
15th January 2014, 19:46
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 :D

Uwe
16th January 2014, 06:45
To avoid issues like this: http://qwt.sourceforge.net/qwtinstall.html#COMPILEANDLINKAPP

Uwe