Hi,
i will try to load from txt file date to qvector (Lipids class) and will send this qvector to function setData/addData. If i make a vector in class where is ploting graph its ok, but if i will try from other class, nothing happend.
dialog.cpp:
#include "dialog.h" #include "ui_dialog.h" #include "Lipids.h" //QVector<double> dp1 ={1, 2 ,3 ,4}; //if I used this vectors all its allright //QVector<double> dp2 ={1, 2, 3 , 4}; Dialog::Dialog(QWidget *parent) : QDialog(parent) , ui(new Ui::Dialog) { ui->setupUi(this); ui->plot->setInteraction(QCP::iRangeDrag, true); ui->plot->setInteraction(QCP::iRangeZoom, true); ui->plot->addGraph(); ui->plot->xAxis->setLabel("Temperatura [K]"); ui->plot->yAxis->setLabel("Entalpia [jednostki arbitralne]"); ui->plot->xAxis->setRange(284,316); ui->plot->yAxis->setRange(-5,140); } Dialog::~Dialog() { delete ui; } void Dialog::addPoint() { } void Dialog::plot() { Lipids dmpc1, dmpc2;// This is artifact, from trying different solutions dmpc1.loadDataX();//This is artifact, from trying different solutions dmpc2.loadDataY();//This is artifact, from trying different solutions QVector<double> dp1 = dmpc1.getDataX();//This is artifact, from trying different solutions QVector<double> dp2 = dmpc2.getDataY();//This is artifact, from trying different solutions ui->plot->graph(0)->setData(dp1, dp2); ui->plot->replot(); ui->plot->update(); } void Dialog::on_Start_clicked() { plot(); }
Lipids.cpp:
#include "Lipids.h" #include <iostream> #include <fstream> #include <string> #include <sstream> #include <QVector> //first I tried load data in one fuction to two vectors, then i changed for this void Lipids::loadDataX() { std::ifstream input; input.open("1.txt", std::ios::in); while(input>>column1>>column2){ lipidX.push_back(column1); } } void Lipids::loadDataY() { std::ifstream input; input.open("1.txt", std::ios::in); while(input>>column1>>column2){ lipidY.push_back(column2); } } QVector<double> &Lipids::getDataX() { return lipidX; } QVector<double> &Lipids::getDataY() { return lipidY; }
Second question, I need to get the graph to draw point by point (with a delay in the appearance of subsequent points - I want to use Sleep(...)). I tried to modify setData() but it only gets a delay of displaying the whole graph, how to get it?
thx for helping