You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

crazycoder

Intermediate

  • "crazycoder" is male
  • "crazycoder" started this thread

Posts: 186

Occupation: Software Engineer

  • Send private message

1

Thursday, April 24th 2008, 11:40am

Drawing a QwtPlot Curve

Hi iam using Qt4.3.3 with VS2005. I am trying to plot a graph with the values pre defined but i am getting this error. And how should i print the system time for every One second on the AxisTitle QwtPlot::xBottom axis. I tried the Qwt Example CPU Plot but i din't understand it properly.

Source code

1
error C3867: 'QWidget::x': function call missing argument list; use '&QWidget::x' to create a pointer to member


here is the .cpp file

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <qwt_plot_marker.h>
#include <qwt_legend.h>
#include <qwt_scale_draw.h>
#include <qwt_math.h>
#include <qwt_plot_item.h>


PlottingGraph::PlottingGraph(QWidget *parent)
	: QDialog(parent)
        , m_curve(0)
	
{
	setupUi(this);
	
    connect(drawButton, SIGNAL(clicked()), this, SLOT(draw()));
	QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
    timer->start(1000);
   	
	{
	 double x[3]={1,2,7};
	 double y1[3]={1,2,3};
	}

        myPlot->setTitle("Temperature Channel");
	myPlot->setAxisTitle(QwtPlot::xBottom, "System Uptime [h:m:s]");
	myPlot->setAxisTitle(QwtPlot::yLeft, "Values");
	myPlot->setAxisScale(QwtPlot::yLeft, -5, 5);
          
    myPlot->setAutoReplot(true);
}

void PlottingGraph::on_drawButton_clicked()
{

}

void PlottingGraph::draw()

    	{
		        m_curve = new QwtPlotCurve();
 			m_curve->setPen(QPen(Qt::red));
	                m_curve->setData(x, y1, 3);
        		QwtPlotGrid *gridy = new QwtPlotGrid();
	                gridy->attach(myPlot);
		        m_curve->attach(myPlot);

}


-----------PlottingGraph.h------------

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "ui_plottinggraph.h"
#include "qwt_plot.h"

class PlottingGraph : public QDialog, public Ui::PlottingGraph
{
	Q_OBJECT

public:
	PlottingGraph(QWidget *parent = 0);
	
private slots:
        void on_drawButton_clicked();
        void draw();
	void showTime();

private:
    QwtPlotCurve *m_curve;
	   
};
#endif// PLOTTINGGRAPH_H


Pls help me out friends.

Thank You

2

Friday, April 25th 2008, 9:30am

at which line does the error occur?

also, 'm_curve = new QwtPlotCurve();' and 'QwtPlotGrid *gridy = new QwtPlotGrid();' must be in your constructor: now you 'new' everytime the timer signal fires, and you never delete. If your program runs for a few days, you'll be out of memory.
madinsjamania

crazycoder

Intermediate

  • "crazycoder" is male
  • "crazycoder" started this thread

Posts: 186

Occupation: Software Engineer

  • Send private message

3

Friday, April 25th 2008, 10:04am

QwtPlot Curve

Hi pls tell me about this i din't understand it. I will be very thank full to you.
What do i have to delete every time the timer signal is fired. I was clueless about it until now. Hey and how do i print the time stamp on the Bottom X axis of the Qwt Plot Widget.

Source code

1
2
3
4
5
6
7
8
9
10
11
void PlottingGraph::draw()

    	{
		        m_curve = new QwtPlotCurve();
 			m_curve->setPen(QPen(Qt::red));
	                m_curve->setData(x, y1, 3);  // ----> Error here
        		QwtPlotGrid *gridy = new QwtPlotGrid();
	                gridy->attach(myPlot);
		        m_curve->attach(myPlot);

}


Thank You

4

Friday, April 25th 2008, 10:33am

you should only create and delete the QwtPlotCurve and QwtPlotGrid once, instead of everytime you draw. New and delete are considered slow operations.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
PlottingGraph::PlottingGraph
{
  m_curve = new QwtPlotCurve();
  m_curve->setPen(QPen(Qt::red));
  m_Grid = new QwtPlotGrid();
  m_Grid->attach(myPlot);
  m_curve->attach(myPlot);
  //rest of initialization
}

PlottingGraph::~PlottingGraph
{
  delete m_Curve;  
  delete m_Grid;
}

void PlottingGraph::draw()
{
  m_curve->setData(x, y1, 3);  // ----> Error here
}


error happens because x() is a method of QWidget, so choose another name for your mamber variable

to set the timestamp: look at setAxisTitle() or so
madinsjamania

crazycoder

Intermediate

  • "crazycoder" is male
  • "crazycoder" started this thread

Posts: 186

Occupation: Software Engineer

  • Send private message

5

Friday, April 25th 2008, 1:00pm

Drawing a QwtPlot Curve

Hi thank You so much for the reply. Hey but once i change the x to z i get a new
error undeclared identifier. !! Hey and i tried modifying the Digital clock program to invoke the system time and print but i get some error's. You have any example code to Time Stamp the systems time on to the Qwt Plot Widget Bottom Axis. It will be very helpfull for me.


Thank You Again.

6

Friday, April 25th 2008, 1:04pm

can't help you with the errors if you don't provide code..
if you use QTime::currentTime().toString() you have the system time in a string..
madinsjamania

crazycoder

Intermediate

  • "crazycoder" is male
  • "crazycoder" started this thread

Posts: 186

Occupation: Software Engineer

  • Send private message

7

Friday, April 25th 2008, 2:00pm

System Time.

Hi Stinos i tried the QTime::currentTime().toString(); but i get a error. I am trying to get a System Time stamp on the Bottom X axis like the Qwt example Cpu Plot.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void PlottingGraph::draw()
{
	m_time++;
	memmove(m_y, &m_y[1], 99 * sizeof(double));
	m_y[99] = 1000 * sin((double)m_time / 360 * 3.1415 * 100) + rand() % 4000 - 2000;
	for (int i = 0; i < 100; i++)
            m_x[i]++;
	if (!m_curve)
	{
		        m_curve = new QwtPlotCurve();
                m_curve->setPen(QPen(Qt::red));
                m_curve->setData(m_x, m_y, 100);
				QwtPlotGrid *gridy = new QwtPlotGrid();
	            gridy->attach(myPlot);
		        m_curve->attach(myPlot);
    }
    m_curve->setData(m_x, m_y, 100);

    QTime::currentTime().toString();
    QString s;
    myPlot->setAxisScale(QwtPlot::xBottom, s);    // I get this error [ error C2660: 'QwtPlot::setAxisScale' : function does not take 2 arguments]
}

?(
Thank You

8

Friday, April 25th 2008, 2:16pm

it's setAxisTitle, not setAxisScale ;)
madinsjamania

crazycoder

Intermediate

  • "crazycoder" is male
  • "crazycoder" started this thread

Posts: 186

Occupation: Software Engineer

  • Send private message

9

Saturday, April 26th 2008, 10:36am

System Time.

Hi Stinos i changed the setAxisTitle to setAxisScale . I got no errors when i debugged the program but the Time is not displayed on the Bottom Axis. I wanted the time to be updated like the Cpu Plot program. But no luck here. :)

Thank You

10

Saturday, April 26th 2008, 11:56am

what does setAxisTitle( QwtPlot::xBottom, QTime::currentTime().toString() ) display then??
madinsjamania

crazycoder

Intermediate

  • "crazycoder" is male
  • "crazycoder" started this thread

Posts: 186

Occupation: Software Engineer

  • Send private message

11

Saturday, April 26th 2008, 12:38pm

System Time.

Hi stinos Thanks a lot for the reply. Finally i see time which is on the title but that is not exactly what i wanted. I wanted the time to be displayed every 2 seconds on the Scale. The Plot will be real time so the Graph Plot keeps updating and i will have to update the scale every 2 seconds. I have attached output screen shot i am getting right now (Present Output.bmp) . I wanted the time to be Stamped like this (Required Output.bmp).

Thank You
crazycoder has attached the following files:

12

Sunday, April 27th 2008, 10:45am

well then you'll need setAxisScale and setAxisScaleDraw. Study the CpuPlot example code to see how they do it; I would guess they override QwtScaleDraw with a custom class that turns samples into time values
madinsjamania