Qwt - Plotting Problem
-
Hello guys.
I want to plot functions with Qwt. I found a example about this. But example is complicated. I dont understand.
I have datas (x and y). How can i plot x and y line this ptoho?
Photo link: http://qwt.sourceforge.net/sinus.png
Example link: http://svn.code.sf.net/p/qwt/code/branches/qwt-6.0/examples/refreshtest/
-
The easiest way is to put the data into a QVector<double> then set the samples on the curve.
I usually subclass a Qwt Plot, create my plot curves in the constructor of the class, then have a function that sets the data on the plot curve (make sure the plot curve is attached to the plot), then call replot().
The examples are going to be your best bet! They are very informative!
-
I have tried but I cant do that. Everytime I have gotten error. Could you write a basic example? Please.
plot.h
@
...
#include <QWidget>#include <qwt_plot.h>
#include <qwt_plot_curve.h>class Plot : public QwtPlot
{
Q_OBJECT
public:
explicit Plot(QWidget *parent = 0);
...
}
@plot.cpp
@Plot::Plot(QWidget *parent) :
QwtPlot(parent)
{QwtPlot *myPlot = new QwtPlot("Two Curves");
...
}@error: no matching function for call to 'QwtPlot::QwtPlot(const char [11])'
Where should i change?
-
Did you check the documentation of "QwtPlot?":http://qwt.sourceforge.net/class_qwt_plot.html#a12888a2101ba2091db0e4710c6a109cb
It is asking for QwtText. It does not automatically convert from char[...].
Try this:
@Plot::Plot(QWidget *parent) :
QwtPlot(parent)
{QwtPlot *myPlot = new QwtPlot( QString ("Two Curves") );
...
}
@ -
[quote author="koahnig" date="1365334930"]Did you check the documentation of "QwtPlot?":http://qwt.sourceforge.net/class_qwt_plot.html#a12888a2101ba2091db0e4710c6a109cb
It is asking for QwtText. It does not automatically convert from char[...].
Try this:
@Plot::Plot(QWidget *parent) :
QwtPlot(parent)
{QwtPlot *myPlot = new QwtPlot( QString ("Two Curves") );
...
}
@[/quote]
Yes you right. It works.
I have a problem with setData(). How can i fix the error? I must use QVector?
error: no matching function for call to 'QwtPlotCurve::setData(double [5], double [5], int)'plot.cpp
@
...double a[5] = { 1, -2, 30, -40, 5}; double b[5] = { -100, 20, -30, 400, 50};
...
curve1->setData(a,b,5);
@ -
Do you mean setSamples ?
-
Yes setSamples() works. How can i use setData()?
What do you think about the curve? I think something is wrong.
Photo Link: http://b1304.hizliresim.com/18/9/lx94g.jpg
-
Like the error is reporting there is no setData that takes two double arrays and an int.
"That's":http://qwt.sourceforge.net/class_qwt_plot_series_item.html#adba072515f7c71c923985882129878c4 the only setData I know of
Can't really comment on the photo, I don't know how you setup your plot. Can you share the code ?
-
Okey. Here my codes.
plot.h
@#ifndef PLOT_H
#define PLOT_H#include <QWidget>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>class Plot : public QwtPlot
{
Q_OBJECT
public:
Plot(QWidget* = NULL);//signals:
//public slots:
};
#endif // PLOT_H
@plot.cpp
@#include "plot.h"Plot::Plot(QWidget *parent) :
QwtPlot(parent)
{double a[5] = { 1, -2, 30, -40, 5};
double b[5] = { -13, 20, -30, 40, -50};QwtPlotCurve *curve1 = new QwtPlotCurve(QString("Curve 1"));
QwtPlotCurve *curve2 = new QwtPlotCurve(QString("Curve 2"));curve1->setPen(QPen(Qt::black, 1));
curve2->setPen(QPen(Qt::red, 1));curve1->attach(this);
curve2->attach(this);curve1->setRawSamples(a, b, 5);
setTitle("Wave Curve"); setAxisTitle(QwtPlot::xBottom, "Seconds"); setAxisScale(QwtPlot::xBottom, 0, 1); setAxisTitle(QwtPlot::yLeft, "Waves"); setAxisScale(QwtPlot::yLeft, -100, 100); setCanvasBackground(Qt::white); replot();
}@
-
I add some codes to pro file, and I got "The program has unexpectedly finished." error when I try to compile. How to fix this?
@INCLUDEPATH += C:/QtSdk/qwt-6.0.0-rc4/src
win32:LIBS += C:/QtSdk/qwt-6.0.0-rc4/lib/libqwtd.a
win32:QMAKE_POST_LINK = copy /Y C:\QtSdk\qwt-6.0.0-rc4\lib\qwtd.dll $(DESTDIR)
CONFIG +=qwt@ -
[quote author="koahnig" date="1365845732"]Which did finish unexpectedly?
Probably you have rerun qmake. [/quote]I click the run button and I show that error message. Program.exe didn't open. How can i rerun qmake?
[quote author="franku" date="1365846514"]You are providing temporary objects a und b to curve1->setRawSamples(a, b, 5); They only live inside the constructur. Probably this could result into you problem. [/quote]
If I understand to you truly; I declare a and b variables in plot.h, a and b take values in constructor plot.cpp. Problem wasn't fixed.
-
[quote author="kingsta" date="1365847361"][quote author="koahnig" date="1365845732"]Which did finish unexpectedly?
Probably you have rerun qmake. [/quote]I click the run button and I show that error message. Program.exe didn't open. How can i rerun qmake?
[/quote]On left side there is the list with projects. Go to the project in question and press right mouse button. An entry with "run qmake" is there.
BTW if the problem from before still exists, this will not cure the problem. franku is right that the temporary declaration is the problem.
@
static double a[5] = { 1, -2, 30, -40, 5};
static double b[5] = { -13, 20, -30, 40, -50};
@will solve your problem for the time being in a very crude way.
Personally, I would recommend that you get a bit more familiarization with "C++ and pointers.":http://bit.ly/16TMY9C -
[quote author="koahnig" date="1365848437"][quote author="kingsta" date="1365847361"][quote author="koahnig" date="1365845732"]Which did finish unexpectedly?
Probably you have rerun qmake. [/quote]I click the run button and I show that error message. Program.exe didn't open. How can i rerun qmake?
[/quote]On left side there is the list with projects. Go to the project in question and press right mouse button. An entry with "run qmake" is there.
BTW if the problem from before still exists, this will not cure the problem. franku is right that the temporary declaration is the problem.
@
static double a[5] = { 1, -2, 30, -40, 5};
static double b[5] = { -13, 20, -30, 40, -50};
@will solve your problem for the time being in a very crude way.
Personally, I would recommend that you get a bit more familiarization with "C++ and pointers.":http://bit.ly/16TMY9C [/quote]I use static variable and there is a kind of weird problem.
There is no curve on display.
@
static double a1[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
static double b1[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};curve2->setRawSamples(a1, b1, 10);
@Weird curve.
@
static double a1[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
static double b1[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};curve2->setRawSamples(a1, b1, 11); // If I write a number is greater than 10, Display a wrong curve again
@
Qt plot the curve which is not my wish again.I add the pro file this code to compile this files. I know Its a bad thing.
@include( examples.pri )@Examples.pri, exaples.pro files are in Qwt Examples.
Examples.pri: http://svn.code.sf.net/p/qwt/code/branches/qwt-6.0/examples/examples.priNow I cant add "public slots" in header file.
my mainwindow.h file;
@#include <QMainWindow>class QStandardItemModel;
class QAction;
class QMenu;namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
enum Mode {ImportingMode, AnalyzingeMode, FilteringMode};public slots: // line 23
void importData(); // line 24
...
@Line 23: error: expected ':' before 'slots'
Line 24: error: expected primary-expression before 'void'
Line 24: error: ISO C++ forbids declaration of 'slots' with no type
Line 24: error: expected ';' before 'void'I create plot.h, plot.cpp as you say
What should I do? -
example.pri is not meant to be included like you do it.
I think it's screwing up your own project.
-
[quote author="SGaist" date="1366615003"]example.pri is not meant to be included like you do it.
I think it's screwing up your own project.
[/quote]
You right. I should do by different way.
We use Q_SLOTS when we add some 3rd party library. It works.
@public Q_SLOTS:@I have a problem again. I can't remove the curve on screen. I write that code. When I run the program, Program is crushed.
header file
@Plot plot1;@Source file
@plot1->detachItems();@How can i remove only the curve?
-
Plot plot1 <= instance of Plot
plot1->detachItems() <= pointer to instance of Plot
Got a NULL pointer ?