display a plot point by point
hello :)
i finally downloaded qwt from svn and everything is ok (Qt 4.5 ,qwt 5.3.0,windows xp)
now i need to display a plot point by point ,so i tried to create a retard with Qtimer ,but it doesn't work !
no execution or complilation errors but i haven't the result i'm expecting
it's my first program with qwt ,i'm following the pdf given with qwt 5.1.1
the documentation for qwt 5.1.1 still useful ?
thanks in advance :)
Re: display a plot point by point
maybe i'm not clear :(
i simply want to see plot painting point by point because i'm working on a "real-time" application ,points will be available while my system is running ,so i plan to use Qthread to synchronize tasks .
now i need to know how can i control displaying plots ?
can i find signals or create signals to do such thing ?
thanks for your help :)
Re: display a plot point by point
Re: display a plot point by point
i just tried a code which stored data first ,after it display the curve
Code:
#include <QtGui>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_text.h>
#include <math.h>
{
public:
Plot();
};
Plot::Plot()
{
double x[100];
double y1[100];
double y2[100];
for(int i=0;i<100;i++){
x[i]=i;
y1[i]=i*i;
y2[i]=i;
}
setTitle("Vitesse et angle de braquage en fonction du temps");
// Set axes
setAxisTitle(xBottom, "Temps");
setAxisScale(xBottom, 0.0, 100);
setAxisTitle(yLeft, "");
setAxisScale(yLeft, 0.0, 100);
// add curves
curve1
->setPen
(QPen(Qt
::green));
curve1->attach(this);
curve1->setData(x, y1, 100);
curve2
->setPen
(QPen(Qt
::red));
curve2->attach(this);
curve2->setData(x, y2, 100);
// ...a horizontal line ...
mY
->setLabel
(QString::fromLatin1("t ( ms )"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->attach(this);
// ...a vertical line ...
mX
->setLabel
(QString::fromLatin1("V ( m/s ) ,Ang ( rad/s )"));
mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mX->attach(this);
}
int main(int argc, char **argv)
{
Plot *myPlot = new Plot();
myPlot->autoRefresh();
myPlot->resize(600,400);
myPlot->show();
return a.exec();
}
i want to change this code to display the curve step by step from (0,0) until (n,m) while time progressing !
Re: display a plot point by point
So where is your timer code?
Re: display a plot point by point
i don't know where should i put timer .
i'm asking how can i put timer ?
i may should use other classes not Qwtplot cuz it needs the data stored to display curves .
i tried with timer somewhere but it doesn't seem to work !
i think i have to use others classes or some signals to control painting process .
Re: display a plot point by point
You should start a timer somewhere in your code and connect its timeout() signal to a custom slot that you have to implement. Inside the slot simply add more data to the curves.
Re: display a plot point by point
all data is fixed in constructor and can't be anywhere else .
i think constructor can't be dynamic ,it's fixed since we instance an object from its class .
if constructor still running when application is running that's mean is using more than thread ,that's can be right ?
can i call constructor many times to change object's value and display it using timer ? i don't think so !
Re: display a plot point by point
In the constructor you can store the data in some array. Then you can add the data to the plot in some other place (like a slot).
Re: display a plot point by point
thanks for your help ,
i'll try but logically data in constructor should be given only one time .
Re: display a plot point by point
I think you don't understand me. You can keep the data in two places - one of them is initialized and filled with data in the constructor. The other is the plot itself that is fed with the data from the first container using a timer.
Here is a skeleton of a code doing what I mean:
Code:
X::X(){
for(int i=0;i<100;i++){
x[i]=i;
y1[i]=i*i;
y2[i]=i;
}
curve1
= new QwtPlotCurve("Vitesse");
// curve1 is a member variable currentPointPosition = 1; // currentPointPosition is a member variable
updateData();
connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
timer->start(500);
//...
}
void X::onTimeout(){
currentPointPosition++;
if(currentPointPosition>100) currentPointPosition = 1;
updateData();
}
void X::updateData(){
curve1->setData(x, y1, currentPointPosition);
}
Re: display a plot point by point
hello ,
thanks for the skeleton,i'm trying to apply your idea but i get blocked is something .
when i define the macro Q_OBJECT an error appear :
Code:
undefined refrence to vtabe for plot
my .pro is :
Code:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += C:\svn\qwt\qwt\src
LIBS += C:\svn\qwt\qwt\lib\qwtd5.dll
CONFIG += debug
# Input
SOURCES += main.cpp
main.cpp :
Code:
{
//Q_OBJECT
public:
Plot();
void pointByPoint();
private :
int currentPointPosition;
double *x;
double *y;
/*
public slots:
void onTimeout(); */
};
Plot::Plot()
{
x=new double[100];
y=new double[100];
for(int i=0;i<100;i++){
x[i]=i;
y[i]=i*i;
}
//......
//connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
}
/*
void Plot::onTimeout(){ //each timeout data will
currentPointPosition++; // be added to the curve
if(currentPointPosition>100) currentPointPosition = 1;
curve1->setData(x, y1, currentPointPosition);
}
*/
void Plot::pointByPoint(){ //calling this method provoque painting curve "slowly"
while(true){
timer->start(500);
}
}
int main(int argc, char **argv)
{
Plot *myPlot = new Plot();
myPlot->autoRefresh();
myPlot->resize(600,400);
myPlot->show();
//myPlot->pointByPoint();
return a.exec();
}
thanks for your help :)
Re: display a plot point by point
Did you remember to run qmake after you added the macro?
Re: display a plot point by point
ohhh ,sorry ,i'm working with Qt creator and i forgot about qmake !!
thanks a lot :)
it works first time but now :
this code still make error : undefined reference to "vtable for plot"
Code:
{
Q_OBJECT
public:
Plot();
void pointByPoint();
private :
int currentPointPosition;
double *x;
double *y;
public slots:
void onTimeout();
};
Plot::Plot()
{
x=new double[100];
y=new double[100];
for(int i=0;i<100;i++){
x[i]=i;
y[i]=i*i;
}
//........
connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
}
void Plot::onTimeout(){ //each timeout data will
currentPointPosition++; // be added to the curve
if(currentPointPosition>100) currentPointPosition = 1;
curve->setData(x, y, currentPointPosition);
}
void Plot::pointByPoint(){ //calling this method provoque painting curve "slowly"
for(int i=0;i<200;i++){
timer->start(500);
}
}
int main(int argc, char **argv)
{
Plot *myPlot = new Plot();
myPlot->autoRefresh();
myPlot->resize(600,400);
myPlot->show();
myPlot->pointByPoint();
return a.exec();
}
it's a shame to ask many questions but there is no documentation about qwt and i'm still beginner .
thanks for your help :)
Re: display a plot point by point
Your issues are not related to Qwt. I'm even thinking about moving the thread to the newbie section of the board.
The Q_OBJECT macro has to be placed in a header file (with .h extension). It's possible to place it in an implementation file but it requires some additional work so let's try avoiding it for now. So if your class declaration is in an implementation (.cpp) file, move it to a header file, add the file to your project and rerun qmake and make.
Re: display a plot point by point
ok, i did but macro problem persist like this :
D:/P2M/courbe/debug/courbe.exe exited with code 0
Starting D:/P2M/courbe/debug/courbe.exe...
D:/P2M/courbe/debug/courbe.exe exited with code -1073741819
if i make macro and slots as a comment everything seems work !
thx again :)
Re: display a plot point by point
If your application crashes, it's not because of lack or presence of Q_OBJECT macro. Use a debugger to see where it crashes and why.
Re: display a plot point by point
i don't know how to debug in console mode but i tried with qt creator .
when i run debug mode ,it still running with no information given ,debugger don't run until the first break point , it's written dbg running .
plot.h :
Code:
#include <QtGui>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_text.h>
#include <math.h>
{
Q_OBJECT
public:
Plot();
~Plot();
void pointByPoint();
private :
int currentPointPosition;
double *x;
double *y;
public slots:
void onTimeout();
};
plot.cpp :
Code:
#include "plot.h"
Plot::Plot()
{
x=new double[100];
y=new double[100];
for(int i=0;i<100;i++){
x[i]=i;
y[i]=i*i;
}
currentPointPosition=1;
setTitle("Vitesse et angle de braquage en fonction du temps");
// Set axes
setAxisTitle(xBottom, "Temps");
setAxisScale(xBottom, 0.0, 100);
setAxisTitle(yLeft, "");
setAxisScale(yLeft, 0.0, 100);
// add curves
curve
->setPen
(QPen(Qt
::green));
curve->attach(this);
curve->setData(x, y, currentPointPosition);
// ...a horizontal line ...
mY
->setLabel
(QString::fromLatin1("t ( ms )"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->attach(this);
// ...a vertical line ...
mX
->setLabel
(QString::fromLatin1("V ( m/s ) ,Ang ( rad/s )"));
mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mX->attach(this);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
}
void Plot::onTimeout(){ //each timeout data will
currentPointPosition++; // be added to the curve
if(currentPointPosition>100) currentPointPosition = 1;
curve->setData(x, y, currentPointPosition);
}
void Plot::pointByPoint(){ //calling this method provoque painting curve "slowly"
for(int i=0;i<200;i++){
timer->start(500);
}
}
Plot::~Plot(){
delete x;
delete y;
}
main.cpp
Code:
#include "plot.h"
int main(int argc, char **argv)
{
Plot *myPlot = new Plot();
myPlot->autoRefresh();
myPlot->resize(600,400);
myPlot->show();
myPlot->pointByPoint();
return a.exec();
}
.pro :
Code:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += C:\svn\qwt\qwt\src
LIBS += C:\svn\qwt\qwt\lib\qwtd5.dll
CONFIG += debug
# Input
SOURCES += main.cpp \
plot.cpp
HEADERS += plot.h
i made as comment Q_OBJECT and my slot and it works ,i checked debugger too,it's ok with it under Qtcreator .
Re: display a plot point by point
I'm sorry but I won't debug your code for you, you have to do that.
Re: display a plot point by point
No , I'm sorry ,
i show the code cuz i suppose there is a simple mistake i can't see it as a Qt beginner .