PDA

View Full Version : QT GUI is running (need to refresh the plot for new data with pushbutton)



Fahed
28th April 2011, 13:24
Hi,

I have implemented simple qwt plot application and i have added pushbutton this application reads data from bin file and plots it.

Now when i start application it plots the data from file, now I want
"on button press(which will invoke comand based program and save new bin file in same diractory) to capture new data and put in the file and after that it shud refresh the plot with new file.
but some how its not working.
here is my code


int main(int argc, char **argv)
{

QApplication a(argc, argv);
Plot plot;
QPushButton FFT("FFT",&plot);
FFT.resize(75, 30);
FFT.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&FFT, SIGNAL(clicked()), &Plot(), SLOT(replot()));
plot.resize(600,400);
plot.show();


return a.exec();
}

//////////////////

I want to run following code again when i press the pushbutton FFT

system("./readwritegpp readwrite.out 0xC4F5B000 16392 1");
FILE *fin;
float *ptr;

fin = fopen( "test.bin", "rb" ); //rb means read-binary

for (int count=0; count<4096 ; count++)
{
fread( &val[count], 1, 4, fin ); //size of float = 4 bytes
nPoints[count]=count;
fft_db[count]=val[count];

}

fclose(fin);
fft->setData(nPoints, fft_db, 4096);



can anyone help me?

high_flyer
28th April 2011, 14:38
I want to run following code again when i press the pushbutton FFT
all you have to do is pack that code in to a slot, and connect the clicked() signal from the button to this slot.

Fahed
29th April 2011, 11:47
thank you, well I have declared a new slot and put this code in its implementation

but when i compile code it gives
Object::connect: No such slot QwtPlot::checkValues()

this is my code


#include <qapplication.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_data.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include <math.h>
#include <QFile>
#include <QLabel>
#include <QDataStream>
#include <QTextStream>
#include <iostream>
#include <fstream>
#include <QPushButton>
#include <stdlib.h>
#include <QFont>
#include <qobject.h>
#include <QObject>


/* this is later the memory content in L3 (128kByte)*/

double fft_db[4096];
double nPoints[4096];
float val[4096];
using namespace std;

//-----------------------------------------------------------------
// simple.cpp
//
// A simple example which shows how to use QwtPlot for FFT
//-----------------------------------------------------------------



class Plot : public QwtPlot
{
public:
Plot();

private slots:
void checkValues();


};


Plot::Plot()
{

setAutoReplot(false);
setTitle("Single Tone FFT_Plot");
insertLegend(new QwtLegend(), QwtPlot::RightLegend);

// Set axis titles
setAxisTitle(xBottom, "Fs -->");
setAxisTitle(yLeft, "FFT Magnitude(dB) -->");

// Insert new curves
QwtPlotCurve *fft = new QwtPlotCurve("y = fft(x)");
#if QT_VERSION >= 0x040000
fft->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
fft->setPen(QPen(Qt::blue));
fft->attach(this);
setAxisScale(QwtPlot::xBottom, 0.0, 2048.0);
setAxisScale(QwtPlot::yLeft, 0.0, 160.0);

system("./readwritegpp readwrite.out 0xC4F5B000 16392 1");
FILE *fin;

fin = fopen( "test.bin", "rb" ); //rb means read-binary

for (int count=0; count<4096 ; count++)
{
fread( &val[count], 1, 4, fin ); //size of float = 4 bytes
nPoints[count]=count;
fft_db[count]=val[count];

}

fclose(fin);
fft->setData(nPoints, fft_db, 2048);



// Insert markers

// ...a horizontal line at y = 0...
QwtPlotMarker *mY = new QwtPlotMarker();
mY->setLabel(QString::fromLatin1("y = 0"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->setLineStyle(QwtPlotMarker::HLine);
mY->setYValue(0.0);
mY->attach(this);

// ...a vertical line at x = 2 * pi
QwtPlotMarker *mX = new QwtPlotMarker();
mX->setLabel(QString::fromLatin1("x = 2 pi"));
mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
mX->setLabelOrientation(Qt::Vertical);
mX->setLineStyle(QwtPlotMarker::VLine);
mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
mX->setXValue(M_PI);
mX->attach(this);

replot();

}


void Plot:: checkValues()
{
system("./readwritegpp readwrite.out 0xC4F5B000 16392 1");
}




int main(int argc, char **argv)
{


QApplication a(argc, argv);



Plot plot;

QPushButton FFT("FFT",&plot);
FFT.resize(75, 30);
FFT.setFont(QFont("Times", 18, QFont::Bold));

QObject::connect(&FFT, SIGNAL(clicked()), &Plot(), SLOT(checkValues()));

plot.resize(600,400);

plot.show();


return a.exec();

}

high_flyer
29th April 2011, 13:15
thats because you defined your slot as private.
Define it as public.