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
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
To copy to clipboard, switch view to plain text mode
plotwindow.h
#ifndef PLOTHWINDOW_H
#define PLOTWINDOW_H
#include <QMainWindow>
{
Q_OBJECT
public:
explicit PlotWindow
(QWidget *parent
= 0);
signals:
public slots:
};
#endif // 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
To copy to clipboard, switch view to plain text mode
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
) :{
plot->setTitle(tr("Simple Plot"));
plot->setCanvasBackground(Qt::white);
plot
->setAxisScale
(QwtPlot::yLeft,
0.0,
100);
grid->attach(plot);
curve->setTitle(tr("Points"));
curve
->setPen
(QPen(Qt
::blue,
4));
curve
->setRenderHint
(QwtPlotItem::RenderAntialiased,
true);
curve->setSymbol(symbol);
curve->setSamples(points);
curve->attach(plot);
mainLayout->addWidget(plot);
window->setLayout(mainLayout);
setCentralWidget(window);
this->setWindowTitle(tr("Simple Plot"));
this->resize(600, 400);
}
#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);
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "plotwindow.h"
int main(int argc, char **argv)
{
PlotWindow gw;
gw.show();
return app.exec();
}
#include <QApplication>
#include "plotwindow.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
PlotWindow gw;
gw.show();
return app.exec();
}
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.
Bookmarks