QCustomPlot Discussion and Comments

read time from fileReturn to overview

Hello, have two new problems,I want to read from a text file,There are examples here on the forum and basicaly it works fine, But the first value in my txt is a timestamp (e.g.13:20:20). This timestamp is stored as 0 in my QVector.Second problem: it reads a lott of o values which aren't there and third problem : it reads only every second line.

[code]void MainWindow::on_pushButton_clicked()
{
    // prepare data:
     int line_count=0;
     QString line;
     QVector<double> x(100);
       QVector<double> y1(100);
       QVector<double> y2(100);
       QVector<double> y3(100);
       QVector<double> y4(100);
       QVector<double> y5(100);
       QVector<double> y6(100);
       QVector<double> y7(100);
       QVector<double> y8(100);
       QVector<double> y9(100);
       QVector<double> y10(100);
        //open file
        QFile file("E:\\QT-examples\\mems-rosco-plot2\\logs\\Martin1.txt");
        if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
          QMessageBox::warning(this, "Error", "Failed to open log file (" + m_logger->getLogPath() + ")", QMessageBox::Ok);
        }

        //get data from file and stored as text stream
        QTextStream in(&file);

        while (!in.atEnd())
        {

                line=in.readLine();
                line_count++;

             QString line = in.readLine();// read first line and so on
           
           if (line_count>5)
			{ qDebug() << line;}
           
              QStringList fields = line.split(';');// split the string
         
               x.append(fields.at(0).toDouble()); // take first value and stored into x
               y1.append(fields.at(1).toDouble()); // take second value and stored into y1
               y2.append(fields.at(2).toDouble()); // take third value and stored into y2
               y3.append(fields.at(3).toDouble());
               y4.append(fields.at(4).toDouble());
               y5.append(fields.at(5).toDouble());
               y6.append(fields.at(6).toDouble());
               y7.append(fields.at(7).toDouble());
               y8.append(fields.at(8).toDouble());
               y9.append(fields.at(9).toDouble());
               y10.append(fields.at(10).toDouble());
        }
              qDebug() << x;
              qDebug() << y1;
              qDebug() << y2;
              qDebug() << y3;
              qDebug() << line_count;
   

}
[/code]

and what you get"18:38:22,1411,181,136,91,136,29,13.8,0.74,0,16,1,0,16,34,139,48,452,0,22.5,3.058,16,0,0,16,15,255,146,0,185,255,255,0,0,253,100,0,255,34,255,255,48,132,129,181,255,30,192,36,0,43,192,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2094, 2124, 2114, 2111, 2139, 2145, 2522, 3717, 3405, 3478, 3487, 3468, 3470, 3431, 3420, 3403, 4197, 2743, 1577, 1533, 2419, 1801, 1626, 1594, 1585, 1576, 1542, 1563, 1550, 1562, 1547, 1523, 1549, 1539, 1545, 1512, 1509, 1511, 1522, 1350, 1514, 1404, 1446, 1487, 1508, 1499, 1496, 1510, 1493, 1478, 1478, 1479, 1499, 1480, 1494, 1467, 1495)
QVector(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 181, 181, 181, 181, 181, 181, 181, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 176, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 179, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, 177)
QVector(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136)
91

help is nuch appreciated.

for your second one, you are clearly reading 2 lines. and only keeping the second one. line 30 in your code and line 33.

for the first issue: it looks like the separator is supposed to be a ',' and not a ';' and dates dont convert to doubles in strings. if you have access to write out the information differently, i would write out the msecsSinceEpoch instead of a string, otherwise you can use QDateTime::fromString() and pass in the format of your string to get a date.

Hi Ian,
i changed sth like you said, but i#m still struggling on the time
in line 7

void MainWindow::on_readlog_click_clicked()
{
    // prepare data:
       int line_count=0;
       QString line;

        QVector<float> x= QDateTime::fromString("hh:mm:ss");
         QVector<double> y1(100);
         QVector<double> y2(100);
         QVector<double> y3(100);
         QVector<double> y4(100);
         QVector<double> y5(100);
         QVector<double> y6(100);
         QVector<double> y7(100);
         QVector<double> y8(100);
         QVector<double> y9(100);
         QVector<double> y10(100);
          //open file
          QFile file("C:\\mems-rosco\\logs\\lastlog.txt");
          if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
          {
            QMessageBox::warning(this, "Error", "Failed to open log file (" + m_logger->getLogPath() + ")", QMessageBox::Ok);
          }

          //get data from file and stored as text stream
          QTextStream in(&file);

          while (!in.atEnd())
          {


               QString line = in.readLine();// read first line and so on
              line_count++;
            if (line_count>1)
            {if (line_count==2)
                qDebug() << line;
                QStringList fields = line.split(',');// split the string

               x.append(fields.at(0).toFloat());

               // take first value and stored into x
                 y1.append(fields.at(1).toDouble()); // take second value and stored into y1
                 y2.append(fields.at(2).toDouble()); // take third value and stored into y2
                 y3.append(fields.at(3).toDouble());
                 y4.append(fields.at(4).toDouble());
                 y5.append(fields.at(5).toDouble());
                 y6.append(fields.at(6).toDouble());
                 y7.append(fields.at(7).toDouble());
                 y8.append(fields.at(8).toDouble());
                 y9.append(fields.at(9).toDouble());
                 y10.append(fields.at(10).toDouble());
          }}
                qDebug() << x;
                qDebug() << y1;
                qDebug() << y2;
                qDebug() << y3;
                qDebug() << line_count;
}

this code has error: conversion from 'QDateTime'to non-scalar type 'Qvector<float>'requested.
I#ve tried with char , const char and string already.
Here is part of the file I want to read.
#time,engine-rpm,coolant_temp,ambient_temp,intake_air_temp,fuel_temp,map_kpa,battery_voltage,throttle_pot_voltage,idle_switch,uk1,park_neutral_switch,fault_codes,idle_set_point,idle_hot,uk2,iac_position,idle_error,ignition_advance_offset,ignition_advance,coil_time,uk3,uk4,uk5,ignition_switch,throttle_angle,uk6,air_fuel_ratio,fault_code0,lambda_voltage_mv,lambda_sensor_frequency,lambda_sensor_dutycycle,lambda_sensor_status,closed_loop,long_term_fuel_trim,short_term_fuel_trim,carbon_canister_dutycycle,fault_code1,idle_base_pos,uk7,uk8,ignition_advance2,uk9,idle_error2,uk10,fault_code4,uk11,uk12,uk13,uk14,uk15,uk16,uk17,uk18,uk19
18:38:22,1411,181,136,91,136,29,13.8,0.74,0,16,1,0,16,34,139,48,452,0,22.5,3.058,16,0,0,16,15,255,146,0,185,255,255,0,0,253,100,0,255,34,255,255,48,132,129,181,255,30,192,36,0,43,192,58,64,10
18:38:22,1387,181,136,91,136,28,13.8,0.74,0,16,1,0,16,34,139,48,449,0,22,3.056,16,0,0,16,15,255,146,0,186,255,255,0,0,253,100,0,255,34,255,255,48,132,129,200,255,30,192,36,0,43,192,58,64,10

That's not what i meant for the QDateTime

remove line 7 and just make a QVector<double> x;

on line 39, you would replace that with

x.append(QTime::fromString(fields.at(0),"hh:mm:ss").msecsSinceStartOfDay()/1000.0);

i didnt realize it was just a time and not a datetime, this should work. This line will convert your field to a QTime object using fromString(), and then take the time and return the milliseconds since the start of the day (00:00:00) and then divide by 1000.0 to get a double in seconds needed by qcustomplot.

Thank you Ian,
I thought I could get the timestamps easier but that works.