cecchinoSMI
6th March 2014, 15:08
I'm tryng to solve an issue with data rappresentation, I know perfectly (by debug) where the error accure, but the context is not very simple to define, due to the extension of the code. Starting to explain the work:
The program receives datas from a message broker (activeMq)
Store these value in a string variable
Try to show the values received on a diagram
The relevant code (in my opinion) to understand is this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap activelogo("C:/Users/Marco/Desktop/CadCamation/Ifacom.JPG");
ui->label_title->setPixmap(activelogo);
setupDiagram();
connectionReceiver();
}
In the previous code be attention to the function setupDiagram implemented here below:
void MainWindow::setupDiagram(){
ui->widget_diagram2->addGraph();
ui->widget_diagram2->graph(0)->setPen(QPen(Qt::blue));
ui->widget_diagram2->graph(0)->setAntialiasedFill(false);
ui->widget_diagram2->xAxis->setTickLabelType(QCPAxis::ltDateTime);
ui->widget_diagram2->xAxis->setDateTimeFormat("hh:mm:ss");
ui->widget_diagram2->xAxis->setAutoTickStep(false);
ui->widget_diagram2->xAxis->setTickStep(2);
ui->widget_diagram2->yAxis->setLabel("Average Wire vibrations[%]");
ui->widget_diagram2->axisRect()->setupFullAxesBox();
connect(ui->widget_diagram2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->widget_diagram2->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->widget_diagram2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->widget_diagram2->yAxis2, SLOT(setRange(QCPRange)));
ui->widget_diagram2->replot();
}
After this the diagram is setted in the widget object, and is all ok, so at this point the application wait for a data, and once it is received it is passed to the following function like a double type:
void MainWindow::upDateData(double value0){
double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
static double lastPointKey = 0;
if (key-lastPointKey > 0.01) // at most add point every 10 ms
{
ui->widget_diagram2->graph(0)->addData(key, value0);
ui->widget_diagram2->graph(0)->removeDataBefore(key-8);
ui->widget_diagram2->graph(0)->rescaleValueAxis();
lastPointKey = key;
}
ui->widget_diagram2->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
ui->widget_diagram2->replot();
}
the issue is in the last line, when I try to execute ui->widget_diagram2->replot(), some bad happen and this is the error:
10112
The program receives datas from a message broker (activeMq)
Store these value in a string variable
Try to show the values received on a diagram
The relevant code (in my opinion) to understand is this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap activelogo("C:/Users/Marco/Desktop/CadCamation/Ifacom.JPG");
ui->label_title->setPixmap(activelogo);
setupDiagram();
connectionReceiver();
}
In the previous code be attention to the function setupDiagram implemented here below:
void MainWindow::setupDiagram(){
ui->widget_diagram2->addGraph();
ui->widget_diagram2->graph(0)->setPen(QPen(Qt::blue));
ui->widget_diagram2->graph(0)->setAntialiasedFill(false);
ui->widget_diagram2->xAxis->setTickLabelType(QCPAxis::ltDateTime);
ui->widget_diagram2->xAxis->setDateTimeFormat("hh:mm:ss");
ui->widget_diagram2->xAxis->setAutoTickStep(false);
ui->widget_diagram2->xAxis->setTickStep(2);
ui->widget_diagram2->yAxis->setLabel("Average Wire vibrations[%]");
ui->widget_diagram2->axisRect()->setupFullAxesBox();
connect(ui->widget_diagram2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->widget_diagram2->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->widget_diagram2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->widget_diagram2->yAxis2, SLOT(setRange(QCPRange)));
ui->widget_diagram2->replot();
}
After this the diagram is setted in the widget object, and is all ok, so at this point the application wait for a data, and once it is received it is passed to the following function like a double type:
void MainWindow::upDateData(double value0){
double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
static double lastPointKey = 0;
if (key-lastPointKey > 0.01) // at most add point every 10 ms
{
ui->widget_diagram2->graph(0)->addData(key, value0);
ui->widget_diagram2->graph(0)->removeDataBefore(key-8);
ui->widget_diagram2->graph(0)->rescaleValueAxis();
lastPointKey = key;
}
ui->widget_diagram2->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
ui->widget_diagram2->replot();
}
the issue is in the last line, when I try to execute ui->widget_diagram2->replot(), some bad happen and this is the error:
10112