I wrote a very simple aplication: reads a data from a text file and plots it out. Works fine. Now I want to be able to stream the plot so that the following command runs:
my_simple_application | other_application
Tried the following after the plot is displayed:
application reads data .
plot is created.
.
.
grafScree->show(); // No problem up to here
QwtPlotCanvas grafCanvas(grafScree );
if ( grafCanvas.testPaintAttribute( QwtPlotCanvas::PaintCached ) ) cout << "PaintCached activated" << endl; else cout << "PaintCached not activated" << endl;
QPixmap *pmGraf = grafCanvas.paintCache();
if ( pmGraf->isNull() ) cout << "Pixmap not created."<<endl;
if (pmGraf->isQBitmap() ) cout << "It is a bitmap."<<endl;
cout << pmGraf;
Observations:
a) "PaintCached activated" is reported
b) "Pixmap not created." is reported
c) Allthough the pixmap is not created, something gets streamed out ( ¿garbage?)
The command
./prupixmap | display
where display refers to ImageMagick´s program produces the following error
display: no decode delegate for this image format `/tmp/magick-XXj30Mz2'
///////////////////////////
Using:
Qwt 5.2.0
Qt 4.5.2
Suse Linux 10.1
Dell Optiplex 360
///////////////// Full program
#include <iostream>
using std::cerr;
using std::endl;
using std::cout;
using std::cin;
#include <QApplication>
#include <QString>
#include <QStringList>
#include <QFile>
#include <QTextStream>
#include <QVector>
#include <QDateTime>
#include <QPixmap>
#include <QImage>
// Añadidos para incluir Qwt
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qwt_data.h>
//#include <qwt_painter.h>
#include <qcolor.h>
#include <qwt_plot_canvas.h>
// QT_BEGIN_NAMESPACE
// class QRubberBand;
// QT_END_NAMESPACE
int leeVarMet(QString *nArch, QVector<QDateTime> *vDT, QVector<double> *vV );
int leeVarMet(QString &nArch, QVector<QDateTime> *vDT, QVector<double> *vV )
{
QFile aEnt(nArch);
if (!aEnt.open(QIODevice::ReadOnly | QIODevice::Text)){
std::cerr << "No se pudo abrir el archivo de entrada" << endl;
return -1;
}
QTextStream entra(&aEnt);
QString linea = entra.readLine(81);
int c =0;
while (!linea.isNull()) {
// cout << qPrintable(linea) << endl;
QStringList lista = linea.split("\t");
bool ok = false;
if (lista.size() == 2) {
QDateTime dtObj = QDateTime::fromString(lista[0], "yyyy-MM-dd HH:mm:ss");
double temp = lista[1].toDouble(&ok);
if ( ok && dtObj.isValid()){
vDT->append(dtObj);
vV->append( temp );
//Problemas con punteros cout << qPrintable( dtObj.toString("yyyy-MM-dd HH:mm:ss")) << " "<< vV[c] << endl;
c++;
} else {
cerr << "Formato de fecha-hora o de punto flotante incorrecto en linea " << c+1 << endl;
return(-2);
}
} else{
cerr << "No hay dos columnas en linea " << c+1 << endl;
return(-3);
}
linea = entra.readLine();
}
aEnt.close();
return 0;
}
int main(int argc, char **argv)
{
QString sN = "pru384.txt";
// QString sN = QString(argv[1]);
QVector<QDateTime> vFechas;
static QVector<double> vVal;
leeVarMet( sN, &vFechas, &vVal );
QApplication app(argc, argv);
QwtPlot *grafScree = new QwtPlot();
grafScree->setTitle("Grafico de Serie de Tiempo");
// insertLegend(new QwtLegend(), QwtPlot::RightLegend);
grafScree->setAxisTitle(QwtPlot::xBottom, "Tiempo");
// grafScree->setAxisScale(QwtPlot::xBottom, 1,2, 0.1);
// grafScree->setAxisMaxMinor(QwtPlot::xBottom,0);
// grafScree->setAxisTitle(QwtPlot::yLeft, "Autovalores");
// Preparando los valores de pru384.txt
int longX = vVal.size();
double *pY = vVal.data();
double *pX = new double[longX];
QDate fRef(2000, 1, 1);
QTime tRef(0, 0, 0);
for (int f = 0; f < longX; f++) {
pX[f] = (double) fRef.daysTo(vFechas[f].date());
pX[f] += tRef.secsTo(vFechas[f].time())/86400.0;
// cout << pX[f]<< " " << pY[f] <<endl;
}
//
QwtPlotCurve *autoVal = new QwtPlotCurve();
autoVal->setData( pX, pY, 384);
QwtSymbol sym;
sym.setStyle(QwtSymbol::Star1);
sym.setSize(4);
sym.setPen(QColor(Qt::red));
sym.setBrush(QColor(Qt::red));
autoVal->setSymbol(sym);
autoVal->setPen(QColor(Qt::black));
autoVal->setStyle(QwtPlotCurve::Lines);
autoVal->attach(grafScree);
grafScree->resize(800,400);
grafScree->show();
// grafScree->replot();
QwtPlotCanvas grafCanvas(grafScree );
if ( grafCanvas.testPaintAttribute( QwtPlotCanvas::PaintCached ) ) cout << "PaintCached activado" << endl; else cout << "PaintCached desactivado" << endl;
// grafCanvas.setPaintAttribute( QwtPlotCanvas::PaintCached, false);
/* fjsoley@supergajo:~/grafiactual/prupixmap> ./prupixmap
PaintCached activado
No se creó el pixmap.*/
QPixmap *pmGraf = grafCanvas.paintCache();
if ( pmGraf->isNull() ) cout << "No se creó el pixmap."<<endl;
if (pmGraf->isQBitmap() ) cout << "Es un bitmap."<<endl;
// QImage imgGraf = pmGraf->toImage();
// pmGraf->save("grafdin384.png", "PNG", -1);
// cout << pmGraf;
// fjsoley@supergajo:~/grafiactual/prupixmap> ./prupixmap | display
// display: no decode delegate for this image format `/tmp/magick-XXj30Mz2'.
//
return app.exec();
}
Bookmarks