I have looked at your code. It is clear to me from the fact that there are more lines of commented out code than there are non-commented lines that you really don't have any idea how to do what you want. I think you are totally confusing things and making it more difficult than it is. From what I understand, you want to do two things:
1 - Read time and temperature strings from a CSV file and convert them to numbers
2 - Create a Qwt plot that displays the temperature vs . time values as a curve
First, you have to understand that reading the data and plotting the data are completely unrelated activities. So don't mix them all up in the same method (or even the same C++ class). Make a C++ class whose job is to read the data file and return the x and y arrays of doubles. It basically needs three methods and a couple of arrays:
class CSVReader
{
public:
CSVReader() {}
// opens the CSV file, reads the data into time and temperature arrays, returns true if OK, false otherwise
bool readDataFromFile
( const QString & fileName
);
const QVector<double> & temperature() const { return mTemperature; }
const QVector<double> & time() const { return mTime; }
private:
QVector<double> mTemperature;
QVector<double> mTime;
};
class CSVReader
{
public:
CSVReader() {}
// opens the CSV file, reads the data into time and temperature arrays, returns true if OK, false otherwise
bool readDataFromFile( const QString & fileName );
const QVector<double> & temperature() const { return mTemperature; }
const QVector<double> & time() const { return mTime; }
private:
QVector<double> mTemperature;
QVector<double> mTime;
};
To copy to clipboard, switch view to plain text mode
Next, use this class to read the data, then pass the data to your curve:
CSVReader dataSource;
if ( dataSource.readDataFromFile( "myfile.csv" ) )
{
const QVector<double> & temps = dataSource.temperature();
const QVector<double> & times = dataSource.time();
curve->setSamples( times.data(), temps.data(), times.size() ); // makes a copy of the data
}
CSVReader dataSource;
if ( dataSource.readDataFromFile( "myfile.csv" ) )
{
const QVector<double> & temps = dataSource.temperature();
const QVector<double> & times = dataSource.time();
curve->setSamples( times.data(), temps.data(), times.size() ); // makes a copy of the data
}
To copy to clipboard, switch view to plain text mode
That's about as simple as it gets. Please notice, any two QVector<double> instances could be used to build the curve. The fact that the vectors were created by reading a CSV file is completely irrelevant as far as the plot is concerned. A tiny spaceship could land on your PC and a little green man could step out and hand you two vectors, and they would work the same way as far as the plot is concerned.
Bookmarks