PDA

View Full Version : Show System Time Stamp ??



dheeraj
21st April 2008, 09:13
Hi friends i am trying to print the system time as the Bottom X Axis of a QwtPlot Widget. But i am having problem doing it i get so many errors when i compile is there any easier way to do it.I tried the DataPlot example in this program but i have so many errors. Here is the code



#include "qwt_plot.h"
#include "qwt_scale_widget.h"
#include <QTimer>
#include <stdlib.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <QTime>

PlottingGraph::PlottingGraph(QWidget *parent)
: QDialog(parent)
, m_curve(0)
, m_time(0)

{
setupUi(this);
connect(drawButton, SIGNAL(clicked()), this, SLOT(draw()));

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(draw()));
timer->start(300);

for (int i = 0; i < 100; i++)
{
m_x[i] = i;
m_y[i] = 0.0;
}

myPlot->setTitle("Temperature Channel");
myPlot->setAxisTitle(QwtPlot::xBottom, "System Uptime [h:m:s]");
myPlot->setAxisScaleDraw(QwtPlot::xBottom,
new TimeScaleDraw(cpuStat.upTime()));
myPlot->setAxisScale(QwtPlot::xBottom, 0, HISTORY);
myPlot->setAxisTitle(QwtPlot::yLeft, "Values");
myPlot->setAxisScale(QwtPlot::yLeft, -10000, 10000);
myPlot->setAutoReplot(true);
}
void PlottingGraph::on_drawButton_clicked()
{
}
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);
myPlot->setAxisScale(QwtPlot::xBottom, timeData[HISTORY - 1], timeData[0]); //m_time, m_time + 100); // auto replots
QTime time = QTime::currentTime();
myPlot->setAxisScale(QwtPlot::xBottom, time.("h:m:s"));
}


void PlottingGraph::timerEvent(QTimerEvent *)
{
for ( int i = dataCount; i > 0; i-- )
{
for ( int c = 0; c < NCpuData; c++ )
{
if ( i < HISTORY )
data[c].data[i] = data[c].data[i-1];
}
}

cpuStat.statistic(data[User].data[0], data[System].data[0]);

data[Total].data[0] = data[User].data[0] +
data[System].data[0];
data[Idle].data[0] = 100.0 - data[Total].data[0];

if ( dataCount < HISTORY )
dataCount++;

for ( int j = 0; j < HISTORY; j++ )
timeData[j]++;

setAxisScale(QwtPlot::xBottom,
timeData[HISTORY - 1], timeData[0]);

for ( int c = 0; c < NCpuData; c++ )
{
data[c].curve->setRawData(
timeData, data[c].data, dataCount);
}

replot();
}


Thank You

wysota
21st April 2008, 09:18
You could start by showing us the errors.

dheeraj
21st April 2008, 10:50
Hi the reason i din put the error's is because i think there is some thing wrong with the code. I
am not sure if the time stamp code is fine. Can u pls tell me where i am going wrong.

wysota
21st April 2008, 12:54
How do you expect us to analyze your code if we don't know what to look for? You didn't even tell us the nature of the problem. You just said you want a timestamp and that it doesn't compile. Could you please paste the first error you get?