I have C Program , I want to display output from this program in Textbrowser in mainwindow and plot in a widget .
C Program
#include<stdio.h>
void main()
{
int i,j;
while(1)
{
for(i=0;i<6;i++)
{
printf("%d\n",i);
if(i==5)
{
for(j=i-1;j>0;j--)
{
printf("%d\n",j);
}
i=1;
}
}
}
}
its out put is 1,2,3,4,5,4,3,2,1,2,3,....... . i want to plot this value in a graph . I stored this in a Qbyte array and reading it by using QProcess .It displayed in a textbrowser in mainwindow . But plotting from QProcess not occuring
my Qt code :
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QVector<double> data_x(101), data_y(101);
timer.start();
init_line_plot();
x_position = 0;
process = new QProcess();
//connect(process, SIGNAL(readyRead()), this, SLOT(receive()));
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(receive()));
connect(process, SIGNAL(readyReadStandardError()), this, SLOT(receive()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow:n_pushButton_clicked()
{
QProcess process;
process.start("./test2");
process.waitForReadyRead();
QByteArray data =process.readAllStandardOutput();
qDebug() << data;
QByteArray err =process.readAllStandardOutput();
qDebug() << err;
ui->textEdit->append(QString(data));
}
void MainWindow::init_line_plot()
{
ui->customPlot->addGraph();
ui->customPlot->xAxis->setLabel("t");
ui->customPlot->yAxis->setLabel("V");
}
void MainWindow::receive()
{
// recieves data as ASCII string
int datalength = 1000;
char data [1000];
int bytesRead =process->readLine(data, datalength);
data[bytesRead]='\0';
QTextStream out(stdout);
out << data << endl;
addDataPoint(atof(data));
}
void MainWindow::addDataPoint(double datapoint)
{
if (x_position>250)data_x.pop_front();
double ms = timer.elapsed();
data_x.push_back((double)ms/1000);
x_position++;
if (x_position>250) data_y.pop_front();
data_y.push_back(datapoint);
ui->customPlot->graph(0)->setData(data_x,data_y);
ui->customPlot->graph(0)->setPen(QPen(QColor(0,200,0)));
ui->customPlot->setBackground(Qt::black);
ui->customPlot->graph(0)->rescaleAxes();
ui->customPlot->replot();
}
Anyone please help me .....
Bookmarks